Linux OS Commands

 

Linux Commands

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

TERMINAL
CTRL cInterrupt and kill a process
CTRL s
CTRL q
Suspend/Lock the terminal
Resume/Unlock the terminal
SYSTEM INFORMATION
uname -aShow basic system information
cat /etc/*release*Show basic distribution information
hostnameName of computer
whoamiCurrent logged in user name
FILES AND DIRECTORIES LISTING
pwdShow current working directory
lsList files in a directory
ls -aInclude files starting with . or “hidden” files
ls -laShow date and size information of all files
ls -lSSort by file size, largest first
ls -lSrSort by file size, smallest first
ls -ltSort by modification time, newest first
ls -ltrSort by modification time, newest last
ls -lhShow file sizes in Kilo, Mega, Giga
treeList contents of directories in a tree-like format
tree -L NList contents of directories in a tree-like format, limit to N levels
DIRECTORY MANIPULATION
cd path/to/directoryChange the current working directory
mkdir directoryCreate a directory
mkdir -p /path/to/directoryCreate a directory and the sub-directories
rmdir directoryDelete an empty directory
rm -rv directoryDelete a directory and all contents under it recursively
cp -rv directory destination-directoryCopy a directory to a new location
mv -r directory destination-directoryMove a directory to a new location
mv directory new-directoryRename a directory
FILE MANIPULATION
rm fileDelete a file
cp file destination/directoryCopy a file to the destination directory
mv file destination/directoryMove a file to the destination directory
mv file new-fileRename a file
ARCHIVES
tar -cf archive.tar file1 file2 file3Create plain tar archive
tar -czf archive.tar.gz file1 file2 file3Create gzip archive
tar -cjf archive.tar.bz file1 file2 file3Create bzip tar archive
tar -xf archive.tarExtract plain tar archive
tar -xzf archive.tar.gzExtract gzip archive
tar -xjf archive.tar.bzExtract bzip tar archive
zip -r archive.zip directory/ file1 file2 file3Create zip archive
unzip archive.zipExtract zip archive
DISK, DIRECTORY AND FILE DISK USAGE/SIZES
df -hShow all file system disk space usage
du -hs /path/to/directoryShow size of directory
du -hd N /path/to/directoryShow sizes of sub-directories N levels deep
ls -lh /path/to/directoryShow 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/directoryFind files recursively which contains the string foo
See grep explained for more options
PROCESSES
ps -ef | grep process-nameFind process with process-name and get process-id for it
kill process-idTerminate process with process-id
kill -9 process-idForce terminate process with id process-id
topList running processes like Windows Task Manager
DEVELOPER TOOLS
nmList symbols in object file, equivalent of Windows dumpbin.exe
lddList shared library dependencies, equivalent of Windows depends.exe
REMOTE OPERATIONS
ssh user@hostConnect to a remote machine using secure shell ssh
scp path/to/local/file user@host:path/to/remote/directoryCopy local file to remote machine
scp user@host:path/to/remote/file path/to/local/directoryCopy remote file to local machine
scp -r path/to/local/directory user@host:path/to/remote/directoryCopy local directory recursively to remote machine
scp -r user@host:path/to/remote/directory path/to/local/directoryCopy remote directory recursively to local machine
UTILITIES
historyList recently run commands
man commandHelp page for a command
clear or CTRL LClear the terminal screen

Tags:

No responses yet

Leave a Reply

Your email address will not be published.

Latest Comments

No comments to show.