Linux commands cheat sheet

Introduction

Here is yet another Linux commands cheat sheet with a different flavor.

  • It’s not a formal reference list but commands that I use regularly.
  • It’s not meant to be an exhaustive list but more of the absolutely required ones to stay out of trouble.
  • Knowing the command is often not sufficient. You have to figure out the right options. So I’ve also specified the relevant options.

For a man page explanation of the commands, use the link and copy/paste the command.

Commands

System Information
uname -a Show basic system information
cat /etc/*release* Show basic distribution information
hostname Name of computer
whoami Current logged in user name
Files and Directories Listing
pwd Show current working directory
ls List files in a directory
ls -a Include files starting with . or “hidden” files
ls -la Show date and size information of all files
ls -lS Sort by file size, largest first
ls -lSr Sort by file size, smallest first
ls -lt Sort by modification time, newest first
ls -ltr Sort by modification time, newest last
ls -lh Show file sizes in Kilo, Mega, Giga
Directory Manipulation
cd path/to/directory Change the current working directory
mkdir directory Create a directory
mkdir -p /path/to/directory Create a directory and the sub-directories
rmdir directory Delete an empty directory
rm -rv directory Delete a directory and all contents under it recursively
cp -rv directory destination-directory Copy a directory to a new location
mv -r directory destination-directory Move a directory to a new location
File Manipulation
rm file Delete a file
cp file destination/directory Copy a file to the destination directory
mv file destination/directory Move a file to the destination directory
mv file new-file Rename a file
Disk, directory and file disk usage/sizes
df -h Show all file system disk space usage
du -hs /path/to/directory Show size of directory
du -hd N /path/to/directory Show sizes of sub-directories N levels deep
ls -lh /path/to/directory Show file sizes in Kilo, Mega, Giga
Search
find path/to/directory -iname "*.jpg" Find files in a directory and its sub-directories
grep -R "foo" /path/to/directory Find files recursively which contains the string foo
Processes
ps -ef | grep process-name Find process with process-name and get process-id for it
kill process-id Terminate process with process-id
kill -9 process-id Force terminate process with id process-id
Developer Tools
nm List symbols in object file, equivalent of Windows dumpbin.exe
ldd List shared library dependencies, equivalent of Windows depends.exe
Utilities
history List recently run commands
man command Help page for a command
clear or CTRL L Clear the terminal screen

Conclusion

If there are other commonly used commands that you think are missing, do let me know.
You might also find these basic vi/vim commands useful.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s