Linux Shell Command Cheatsheet for Web Developers

Linux

Utility

be root
su – root
sudo -i

show current path
pwd

which user
whoami

find
find /path/to/files/* -name ‘*.png’

find in current directory of the backup drive Desktop Backups
find . -name filename.jpg

find directory – the dot represents the working directory
find . -name ‘render’ -type d

grep
grep ‘render’ /path/to/files/*

run script
sh scriptname.sh

compare directories
diff -q directory-1/ directory-2/

Files

new file
cat > filename.ext
or..
touch filename.ext

rename file
mv filename.txt anotherfilename.txt

delete file
rm filename.ext

change file permission
chmod 664 /path/to/filename.ext

change file owner
chown user:group myfile.txt
in most cases you’ll have to use sudo

Folders

show folder size
du -h nameofdirectory

rename folder
mv /path/to/files/foldername /path/to/files/anotherfoldername

list folder contents
ls -l

create folder
mkdir foldername

delete empty folder
rmdir folderename

delete full folder
rm -r folderename

show dot files
ls -a

list by date
ls -d

list by size
ls -t

list to file
ls -al > filename.txt

get volume sizes
df -h

change folder and group owner
sudo chown daemon:daemon wpforms

SSH
ssh accountname@servername.com

exit
exit

SCP

up
scp file.jpg accountname@servername.com:~/domains/foo.net/html/transfer

down
scp accountname@servername.com:/users/staging/mysql/backups/daily/mysql/mysql_2015-10-19_01h00m.Monday.sql.gz /Users/foo/downloads

directory
scp -r accountname@servername.com:/path/to/remote/directory /path/to/download/directory

cron

The 2>&1 redirects Channel 2 (Standard Error) and Channel 1 (Standard Output) to the same place which in this context is Channel 1 (Standard Output), and thence your log file.

show crontab for current user
cron -l

edit crontab for current user
cron -e

nano

show line numbers
nano -c filename

jump to end of file
nano -c filename Ctrl_ Ctrl V

emacs

save
CTRL-x CTRL-s

search
CTRL-s

close document
CTRL-x, CTRL-c

move
CTRL-x CTRL-s

Leave a Reply

Your email address will not be published. Required fields are marked *