Linux/Unix Cheat Sheet

Linux/Unix Cheat Sheet

Geek ahh! This is what every engineer call himself in current technology world.

If not! You are going to become tech geek after reading this blog.

Linux/Unix is one of the most widely used operating systems in the World. And yet to gain a large share of desktop usage, it powers the overwhelming majority of web servers. Here we are covering the Linux cheat sheets for everything from command line tasks to keyboard shortcuts.

Directory operations:

pwd					    Show current directory
mkdir 					    Make directory dir
cd dir					    Change directory to dir
cd .. 					    Go up a directory
ls					    List files


uname -a				    Show system and kernel
uname -r				    Display kernel release information 
uptime				            Show how long the system has been running + load 
hostname				    Show system host name
hostname 				    Display the IP address of the host
last reboot				    Show system reboot history
cal					    Show this month calendar 
w				            Display who is online
finger user				    Display information about user
head -n1 /etc/issue			    Show distri­bution
mount					    Show mounted filesy­stems
Ddate					    Show system date
Uptime					    Show uptime
whoami				            Show your username
man command			            Show manual for command

Bash Shortcuts:

CTRL-c				            Stop current command
CTRL-z				            Sleep program
CTRL-a				            Go to start of line
CTRL-e				            Go to end of line
CTRL-u				            Cut from start of line
CTRL-k				            Cut to end of line
CTRL-r				            Search history
!!				            Repeat last command
!abc				            Run last command starting with abc
!abc:p				            Print last command starting with abc
!$				            Last argument of previous command
ALT-. 				            Last argument of previous command
!*				            All arguments of previous command
^abc^123			            Run previous command, replacing abc with 123

ls Options:

-a				            Show all (including hidden)
-R				            Recursive list
-r				            Reverse order
-t				            Sort by last modified
-S				            Sort by file size
-l				            Long listing format
-1				            One file per line
-m				            Comma-­separated output
-Q				            Quoted output

Bash Variables:

env				            Show enviro­nment variables
echo $NAME			            Output value of $NAME variable
export NAME=value		            Set $NAME to value
$PATH				            Executable search path
$HOME				            Home directory
$SHELL	                                    Current shell
Disk uses
df –h 				            Show free space on mounted filesystems
df -i 				            Show free inodes on mounted filesystems 
fdisk -l 				    Show disks partitions sizes and types
du -ah 				            Display disk usage in human readable form
du -sh 				            Display total disk usage on the current directory
findmnt			                    Displays target mount point for all filesystem
mount device-path mount-point 		    Mount a device

Nano Shortcuts:

Ctrl-R				            Read file
Ctrl-O				            Save file
Ctrl-X				            Close file

Cut and Paste
ALT-A				            Start marking text
CTRL-K				            Cut marked text or line
CTRL-U				            Paste text

Navigate File
ALT-/				            End of file
CTRL-A				            Beginning of line
CTRL-E				            End of line
CTRL-C				            Show line number
CTRL-_				            Go to line number

Search File
CTRL-W			                    Find
ALT-W				            Find next
CTRL-\				            Search and replace

Search Files:

grep pattern filesgrep pattern files	    Search for pattern in files
grep -i					    Case insens­itive search
grep -r				            Recursive search
grep -v					    Inverted search
grep -o					    Show matched part of file only
find /dir/ -name name*			    Find files starting with name in dir
find /dir/ -user name			    Find files owned by name in dir
find /dir/ -mmin num			    Find files modifed less than num minutes ago in dir
whereis command			            Find binary / source / manual for command
locate file				    Find file (quick search of system index)

File Permissions:

chmod 775 file				    Change mode of file to 775
chmod -R 600 folder			    Recurs­ively chmod folder to 600
chown user:group file		            Change file owner to user and group to group
chown owner-user:owner-group file-name      Change owner and group owner of the file 
chown owner-user:owner-group directory 	    Change owner and group owner of the directory

File Operations:

touch file1				    Create file1
cat file1 file2				    Concat­enate files and output
less file1				    View and paginate file1
file file1				    Get type of file1
cp file1 file2				    Copy file1 to file2
rm file1				    Delete file1
head file1				    Show first 10 lines of file1
tail file1				    Show last 10 lines of file1
tail -F file1				    Output last lines of file1 as it changes
ls –al 					    Display all information about files/ directories 
more file 				    Output contents of file 
wc				            print the number of bytes, words, and lines in files 
xargs				            Execute command lines from standard input


dmesg			                    Detected hardware and boot messages
cat /proc/cpuinfo			    CPU model 
cat /proc/meminfo			    Hardware memory
cat /proc/interrupts		            Lists the number of interrupts per CPU per I/O device
lshw					    Displays information on hardware configuration of the system
lsblk					    Displays block device related information in Linux 
free -m 				    Used and free memory (-m for MB) 
lspci -tv 				    Show PCI devices
lsusb -tv				    Show USB devices 
dmidecode				    Show hardware info from the BIOS 
hdparm -i /dev/sda 			    Show info about disk sda
hdparm -tT /dev/sda			    Do a read speed test on disk sda
badblocks -s /dev/sda			    Test for unreadable blocks on disk sda


ip addr show				    Display all network interfaces and ip address
ip address add dev eth0	    Set ip address
ethtool eth0 				    Linux tool to show ethernet status
mii-tool eth0				    Linux tool to show ethernet status
ping host				    Send echo request to test connection
whois domain				    Get who is information for domain
dig domain				    Get DNS information for domain 
dig -x host 				    Reverse lookup host 
host 			    Lookup DNS ip address for the name 
hostname –i 				    Lookup local ip address 
wget file				    Download file 
netstat -tupl				    Listing all active listening ports

With the above commands your good to go ahead and explore linux.
Have a great time working with Linux! ?
Share us your experiences, Cheers !!