Basic Linux Commands
Useful Basic Linux Commands
File Commands:
ls - Directory listing
ls -al - Formated listing
cd - Change to home
cd <dir> - Change directory to dir
pwd - Show current directory
Shortcuts:
ctrl + c - Halts current command
ctrl + z - Stop current command
fg - Resume stopped command in foreground
bg - Resume stopped command in background
exit - Log out of current sesstion
ctrl + d - Log out of current sesstion
ctrl + w - Erases one word in current line
ctrl + u - Erase whole line
ctrl + r - Reverse lookup of previouse commands
!! - Repeat last command
Searching:
grep <pattern> <filename> - Search for pattern in files
grep -r <pattern> <dir> - Search recursively for pattern in dir
command | grep <pattern> - Search for pattern in the output of command
locate <filename> - Find all instances of file
System Info:
date - Show current date/time
cal - Show this month's calendar
uptime - Show uptime
w - Show who is online
whoami - Who are you logged in as
uname -a - Show kernel config
cat /proc/cpuinfo - CPU info
cat /proc/meminfo - Memory info
man command - Show manual for command
df - utility show free disk space(Hard Disk) on all the file systems
df -h - above information in a human readable format
du - Show directory space usage
du - sh - Human redable size in GB
free - Show memory and swap usage
whereis <appname> - Show possible locations of app
which <appname> - Show which app will be run by default
SSH:
ssh <username>@<host> - Connect to host as user
ssh -p <port> <username>@<host> - Connect using port
ssh -d <port> <username>@<host> - Connect and use bind port
Network:
ping <hostname> - Ping host
whois <domain> - Get whois for domain
dig <domain> - Get DNS for domain
dif -x <host> - Reverse lookup host
wget <filename> - Download file
wget -c <filename> - Continue stop download
wget -r <URL> - Revursively download files from URL
Process Management:
top - utility, show all the running processes on the machine.
Note: Press 'q' to quite
ps - Display currently active process
ps ux - Display all the processes running under a user
ps aux - ps with a lot of detail
ps PID - Show the process status of a single process
pidof <Process_name> - To find the PID of a process
# ------- Terminates Running Processes ---------------
kill <pid> - kill the process with <pid>
killall <process_name> - Kill al process named
bd - lists stopped/background jobs, resumed stopped job in the background
fg - bring most recent job to foreground
fg -n - brings job n to foreground
File Permissions:
chmod octal file - Change permissons of file
4 - read(r)
2 - write(w)
1 - execute(x)
order: owner/group/world
eg:
chmod 777 - rwx for everyone
chmod 755 - rw for owner, rx for group/world
Compression:
tar cf <file>.tar <files> - tar files into file.tar
tar xf <file>.tar - untar into current directory
tar tc <file>.tar - show contents of archive
Tar flags:
c - crete archive j - bzip2 compression
t - table of contents k - do not overwrite
x - extract T - files from file
f - specifies filename w - ask for confirmation
z - use zip/gzip v - verbose
Installation:
./configure
make
make install
Last updated
Was this helpful?