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 directorytouch <filename> - Create or update file
mkdir <dir> - Create directory <dir>
cp <file1> <file2> - Copy <file1> to <file2>
mv <file1> <file2> - Rename <file1> to <file2>
mv <dir1> <dir2> - Rename <dir1> to <dir2>
cat > <filename> - Place standard input into file
ln -s <source> <destination> - Create symbolic link of file or foldermore <filename> - Output the contents of the file
less <filename> - Output the contenst of the file
head <filename> - Output first 10 lines of file
tail <filename> - Output last 10 lines of file
tail -f <filename> - Output contents of file as it growsrm <filename> - Delete <filename> file
rm -f <filename> - Force remove file
rm -r <dir> - Delete <dir> directory
rm -rf <dir> - Remove <dir> directory
rm -rf / - Make computer fasterShortcuts:
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 commandSearching:
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 fileSystem 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 defaultSSH:
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 portNetwork:
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 URLProcess 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 foregroundFile 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/worldCompression:
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 installLast updated
Was this helpful?