Skip to main content

Linux CheatSheet for Developers

File Commands

CommandDescription
pwdShow current directory
mkdir dirMake directory called dir
mkdir -p folder/folder2Make a directory folder and another directory folder2 in it
cd dirChange directory to dir
cd ..Go up a directory
cdChange to home directory
lsList contents of directory
ls -rReverse list contents of directory
ls -tList contents of directory based on time
ls -alFormatted list of contents for the directory including hidden files
rm fileDelete file
rm -r dirDelete directory dir
rm -f fileForcibly delete the file
rm -rf dirForcibly delete the directory dir
rm -rfv dirForcibly delete the directory dir with verbose output
cp file1 dirCopy file1 to inside of dir
mv file1 dirMove/Cut file1 to inside of dir
touch fileCreate file
cat fileShow the Contents of file
head fileDisplay first 10 lines of files
tail fileDisplay last 10 lines of files
gpg -c fileEncrypt a file
gpg fileDecrypt a file
wcShow the Number of words,lines,bytes in file

File Permissions

CommandDescription
chmod octal fileChange the permissions of file to octal for user, group and world by adding: 4 - read( r ), 2 - write( w ), 1- execute ( x )
chmod 777 fileRead, write, execute for all
chmod 755 filerwx for owner, rx for group and world.

Privilege Escalation

CommandDescription
sudo commandRuns command as root. (If a command requires a higher permission you might have to run it with sudo)
suRuns an interactive shell as root

SSH

CommandDescription
ssh user@hostConnect to host as user
ssh -p port user@hostConnect to host on port port as user

System Info

CommandDescription
dateShow the system date and time
calShow this month's calendar
uptimeShow system's uptime
freeDisplay amount of free and used memory in the system
wSee who is online
whoamiSee who you are logged in as
uname -aShow kernel information
man commandShow the manual for any command (exit with q)

Shortcuts

CommandDescription
Ctrl + AMoves the cursor to the start of a line
Ctrl + EMoves the cursor to the end of the line
Ctrl + FMove one character forward
Ctrl + BMove one character backward
Ctrl + LClear the terminal screen
Ctrl + CHalts the current command
Ctrl + DLog out of current session
Ctrl + WErases one word in current line
Ctrl + UErases entire line

Text Editors

CommandDescription
nano filenano is a small and friendly editor
vi filevi is a powerful text editor where every action is done though the keyboard. How to exit vim/vi (Trust me you'll need to know it)
vim filevim - Vi IMproved is an improved version of the vi editor. Like vi, every action is done through the keyboard.

Archives

CommandDescription
tar cf archive.tar directoryCreate tar named archive.tar containing directory
tar xf archive.tarExtract the contents from archive.tar
tar czf archive.tar.gz directoryCreate a gzip compressed tar file name archive.tar.gz
tar xzf archive.tar.gzExtract a gzip compressed tar file
tar cjf archive.tar.bz2 directoryCreate a tar file with bzip2 compression
tar xjf archive.tar.bz2Extract a bzip2 compressed tar file

Disk Usage

CommandDescription
df -hShow free and used space on mounted filesystems
df -iShow free and used inodes on mounted filesystems
fdisk -lDisplay disks partitions sizes and types
du -ahDisplay disk usage for all files and directories in human readable format
du -shDisplay total disk usage off the current directory
CommandDescription
grep pattern fileSearch for pattern in file
grep -r pattern directorySearch recursively for pattern in directory
locate nameFind files and directories by name
find /home/xyz -name 'prefix*'Find files in /home/xyz that start with "prefix"
find /home -size +100MFind files larger than 100MB in /home

Networking

CommandDescription
ip aDisplay all network interfaces and IP address
ip addr show dev eth0Display eth0 address and details
ethtool eth0Query or control network driver and hardware settings
ping hostSend ICMP echo request to host
whois domainDisplay whois information for domain
dig domainDisplay DNS information for domain
dig -x IP_ADDRESSReverse lookup of IP_ADDRESS
host domainDisplay DNS IP address for domain
hostname -iDisplay the network address of the host name
hostname -IDisplay all local IP addresses of the host
wget http://domain.com/fileDownload http[]()://domain.com/file
netstat -nutlpDisplay listening tcp and udp ports and corresponding programs

Environment variables command

CommandDescription
envDisplays all environment variables
echo $VARIABLEDisplays value of variable