linux commands

lots of lovely commands for you.

executing files

make file executable
chmod +x file.txt
execute a file (like a cron)
./file.txt

file and directory sizes

filesystem disk space
df -h
size of directory
du -sh /the/dir/
list of directories and size
du -sh --max-depth=1 /var/www/vhosts/

reading & outputting files

output a file to screen
cat file.txt
append one file to another
cat file1.txt >> file2.txt
view a long file in pages
less file.txt or cat file.txt | less

writing to files

append some text to a file
echo 'hi there' >> file.txt
overwrite a file
echo 'im the new content' > file.txt

grep: finding text within files

find text in a file
cat file.txt | grep -l 'the text'
show all lines except 'this text'
cat file1.txt | grep -v 'this text'

common commands

create symbolic link
ln -s file.txt symlink
copy files in directory
cp the/dir/* new/dir -R
move a file
mv ~stuart/file.txt ~you/
change ownership of directory
chown newuser.newgroup dir/
change permissions of file
chown 644 user.group
make new directory
mkdir newdir/

split large files / join them back together again

split a large file into chunks
split --bytes=2m bigfile.tar bit_
join chunks back together again
cat bit_* >> newbigfile

wget

wget all files of type
wget -r -A.pdf http://www.thewebsite.com/pdfs/
wget entire site like a spider
wget -r http://www.thewebsite.com

tar

compress a directory
tar zcvf thetar.tar dir/
uncompress a directory
tar zxvf thetar.tar
tar shitloads of files (argument list too long stylie)
find -iname '*.JPG' > imageList
tar zcvf feedImages.tar --files-from imageList

listing files and directories

list files that begin with 'stu'
ll stu*
list files that end with 'php'
ll *php
show all files
ls -a
show filesizes human format
ls -h
sort by size
ls -S
sort by modified date
ls -t
reverse order
ls -r
all together now
ls -lahSr

finding files

files with certain characters in their name
find . -type f -name '*index*'
files over a certain size
find . -type f -size +10000k
everything owend by stuart
find . -user stuart
everything with these permissions
find . -perm 777
files changed in the last 3 days
find . -type f -mtime -3 -name '*html'
directories changed in the last 30 minutes
find . -type d -mmin 30 -name '*php'