I thought this would be a great reference for our new and advanced users alike.Thereβs a lot of commands here that I will now use on an every day basis.
System Info
date β Show the current date and time
cal β Show this monthβs calendar
uptime β Show current uptime
w β Display who is online
whoami β Who you are logged in as
finger user β Display information about user
uname -a β Show kernel information
cat /proc/cpuinfo β CPU information
cat /proc/meminfo β Memory information
df β Show disk usage
du β Show directory space usage
free β Show memory and swap usage
Keyboard Shortcuts
Enter β Run the command
Up Arrow β Show the previous command
Ctrl + R β Allows you to type a part of the command youβre looking for and finds it
Ctrl + Z β Stops the current command, resume with fg in the foreground or bg in the background
Ctrl + C β Halts the current command, cancel the current operation and/or start with a fresh new line
Ctrl + L β Clear the screen
command | less β Allows the scrolling of the bash command window using Shift + Up Arrow and Shift + Down Arrow
!! β Repeats the last command
commandΒ !$ β Repeats the last argument of the previous command
Esc + . (a period) β Insert the last argument of the previous command on the fly, which enables you to edit it before executing the command
Ctrl + A β Return to the start of the command youβre typing
Ctrl + E β Go to the end of the command youβre typing
Ctrl + U β Cut everything before the cursor to a special clipboard, erases the whole line
Ctrl + K β Cut everything after the cursor to a special clipboard
Ctrl + Y β Paste from the special clipboard that Ctrl + U and Ctrl + K save their data to
Ctrl + T β Swap the two characters before the cursor (you can actually use this to transport a character from the left to the right, try it!)
Ctrl + W β Delete the word / argument left of the cursor in the current line
Ctrl + D β Log out of current session, similar to exit
Learn the Commands
apropos subject β List manual pages for subject
man -k keyword β Display man pages containing keyword
man command β Show the manual for command
man -t man | ps2pdf β > man.pdfΒ β Make a pdf of a manual page
which command β Show full path name of command
time command β See how long a command takes
whereis app β Show possible locations of app
which app β Show which app will be run by default; it shows the full path
Searching
grep pattern files β 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 file β Find all instances of file
find / -name filename β Starting with the root directory, look for the file called filename
find / -name β*filename*β β Starting with the root directory, look for the file containing the string filename
locate filename β Find a file called filename using the locate command; this assumes you have already used the command updatedb (see next)
updatedb β Create or update the database of files on all file systems attached to the Linux root directory
which filename β Show the subdirectory containing the executable fileΒ called filename
grep TextStringToFind /dir β Starting with the directory called dir, look for and list all files containing TextStringToFind
File Permissions
chmod octal file β Change the permissions of file to octal, which can be found separately for user, group, and world by adding: 4 β read (r), 2 β write (w), 1 β execute (x)
Examples:
chmod 777 β read, write, execute for all
chmod 755 β rwx for owner, rx for group and world
For more options, see man chmod.
File Commands
ls β Directory listing
ls -l β List files in current directory using long format
ls -laC β List all files in current directory in long format and display in columns
ls -F β List files in current directory and indicate the file type
ls -al β Formatted listing with hidden files
cd dir β Change directory to dir
cd β Change to home
mkdir dir β Create a directory dir
pwd β Show current directory
rm name β Remove a file or directory called name
rm -r dir β Delete directory dir
rm -f file β Force remove file
rm -rf dir β Force remove an entire directory dir and all itβs included files and subdirectories (use with extreme caution)
cp file1 file2 β Copy file1 to file2
cp -r dir1 dir2 β Copy dir1 to dir2; create dir2 if it doesnβt exist
cp file /home/dirname β Copy the file called filename to the /home/dirname directory
mv file /home/dirname β Move the file called filename to the /home/dirname directory
mv file1 file2 β Rename or move file1 to file2; if file2 is an existing directory, moves file1 into directory file2
ln -s file link β Create symbolic link link to file
touch file β Create or update file
cat > file β Places standard input into file
cat file β Display the file called file
more file β Display the file called file one page at a time, proceed to next page using the spacebar
head file β Output the first 10 lines of file
head -20 file β Display the first 20 lines of the file called file
tail file β Output the last 10 lines of file
tail -20 file β Display the last 20 lines of the file called file
tail -f file β Output the contents of file as it grows, starting with the last 10 lines
Compression
tar cf file.tar files β Create a tar named file.tar containing files
tar xf file.tar β Extract the files from file.tar
tar czf file.tar.gz files β Create a tar with Gzip compression
tar xzf file.tar.gz β Extract a tar using Gzip
tar cjf file.tar.bz2 β Create a tar with Bzip2 compression
tar xjf file.tar.bz2 β Extract a tar using Bzip2
gzip file β Compresses file and renames it to file.gz
gzip -d file.gz β Decompresses file.gz back to file
Printing
/etc/rc.d/init.d/lpd start β Start the print daemon
/etc/rc.d/init.d/lpd stop β Stop the print daemon
/etc/rc.d/init.d/lpd status β Display status of the print daemon
lpq β Display jobs in print queue
lprm β Remove jobs from queue
lpr β Print a file
lpc β Printer control tool
man subject | lpr β Print the manual page called subject as plain text
man -t subject | lpr β Print the manual page called subject as Postscript output
printtool β Start X printer setup interface
Network
ifconfig β List IP addresses for all devices on the local machine
ping host β Ping host and output results
whois domain β Get whois information for domain
dig domain β Get DNS information for domain
dig -x host β Reverse lookup host
wget file β Download file
wget -c file β Continue a stopped download
SSH
ssh user@host β Connect to host as user
ssh -p port user@host β Connect to host on port port as user
ssh-copy-id user@host β Add your key to host for user to enable a keyed or passwordless login
User Administration
adduser accountname β Create a new user call accountname
passwd accountname β Give accountname a new password
su β Log in as superuser from current login
exit β Stop being superuser and revert to normal user
Process Management
ps β Display your currently active processes
top β Display all running processes
kill pid β Kill process id pid
killall proc β Kill all processes named proc (use with extreme caution)
bg β Lists stopped or background jobs; resume a stopped job in the background
fg β Brings the most recent job to foreground
fg n β Brings job n to the foreground
Installation from source
./configure
make
make install
dpkg -i pkg.deb β install a DEB package (Debian / Ubuntu / Linux Mint)
rpm -Uvh pkg.rpm β install a RPM package (Red Hat / Fedora)
Stopping & Starting
shutdown -h now β Shutdown the system now and do not reboot
halt β Stop all processes β same as above
shutdown -r 5 β Shutdown the system in 5 minutes and reboot
shutdown -r now β Shutdown the system now and reboot
reboot β Stop all processes and then reboot β same as above
startx β Start the X system
Original PostΒ http://community.linuxmint.com/tutorial/view/244
Support Our Threat Intelligence
If you find our CVE report and cybersecurity news helpful, consider supporting our work.