0% found this document useful (0 votes)
157 views

System Info: Command - Less - Allows The Scrolling of The Bash Command Window Using Shift + Up Arrow and

This document provides summaries of Linux system information commands, keyboard shortcuts, file commands, and other common Linux commands. It includes over 50 commands organized into sections on system info, keyboard shortcuts, searching, file permissions, file commands, compression, printing, networking, SSH, user administration, process management, installation from source code, and stopping and starting processes. The document is intended to be a quick reference guide for Linux users to look up syntax and usage for essential commands.

Uploaded by

Marko Sablić
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
157 views

System Info: Command - Less - Allows The Scrolling of The Bash Command Window Using Shift + Up Arrow and

This document provides summaries of Linux system information commands, keyboard shortcuts, file commands, and other common Linux commands. It includes over 50 commands organized into sections on system info, keyboard shortcuts, searching, file permissions, file commands, compression, printing, networking, SSH, user administration, process management, installation from source code, and stopping and starting processes. The document is intended to be a quick reference guide for Linux users to look up syntax and usage for essential commands.

Uploaded by

Marko Sablić
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 8

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 -h 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 its 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 filename called file 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
iwconfig Used to set the parameters of the network interface which are specific to the wireless
operation (for example: the frequency)
iwlist used to display some additional information from a wireless network interface that is not
displayed by iwconfig
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
cd -> Used to navigate the directories. You can move to any location by path.
1. cd This will move you back to your home, same as cd ~
2. cd .. This will take you back exactly one directory. Starting in /home/justin/Desktop, cd ..
will put me into /home/justin. This can be expanded upon, cd ../../ from the Desktop
location instead will move me 2 back, from my Desktop to /home.
3. cd foldername/ This will move you forward to the given folder in your current folder. Take
note of the missing prefix / it is an important omission. if I am in /home/justin and I want to
get to Desktop, I must type cd Desktop/ without the / before Desktop. Typing / before it
places us in the root of file system, which is incorrect.
4. cd /some/other/path This will take you to the specified folder path, supposing it exists as
typed exactly. Don't forget your tab completion!
ls -> Used to list folder contents. You can view many kinds of file and folder attributes.
1. ls By itself, ls will simply list all your files in the current folder. From fact #4, this literally
does ls .
2. ls -l Provides a longer listing format including owners, permissions, size, and date modified.
3. ls -a Displays hidden files and folders as well as the normal listing.
4. ls -al Combine options to display both hidden files and in the long format.
5. ls -h Show file sizes in human readable format (K, M, Gbyte) filesizes instead of bytes.
Often used in conjuction with the -l flag.
6. You can view files in directories you are not even in. If I am in /home/justin/Desktop, and I
want to view a file in /home/justin, I can do ls ../ list files one directory back (and not have
to go back to do so.)
cp -> Copy files
1. cp file /path/to/folder Copies specified file to the given path.
2. cp -r folder /path/to/folder Copies recursively the contents of the folder to another folder.
3. cp *.extension /path/to/folder Copies files matching the given extension to the new folder.
To copy all .doc files, it becomes cp *.doc /path/to/folder and the folder must exist.
4. cp name* /path/to/folder Copies all files starting with 'name' to the given folder. To copy
all files starting with example, it becomes cp example* /path/to/folder and the folder must
exist.
mv -> Move files
1. The syntax of mv is similar to the example above with cp exempt for example #2. mv does
not take the -r flag since moving a folder also moves its contents. The syntax is not exact in

all instances, but works with the above examples. Consult your manpages for more details.
rm -> Remove files
1. For all intents and purposes, removing files via rm is permanent. It does not use the Trash
bin. Use with caution and make sure you are deleting explicitly what you want, not what
you think you want. If you decide to get fancy with your delete commands, it's probably
going to come back to bite you.
2. rm file Remove the specified file from the system.
3. rm -r folder Remove the specified folder from the system
4. rm -rf folder Removes the specified folder forcefully from the system. This command can
severely break your configuration if used incorrectly as it will not prompt you if something
critical is being deleted. If you have to use this, chances are something more is broken or
there was a mistake made. This should only be used as an absolute last resort method
and is not recommended.
nano -> full command line text editor
1. One can edit files using nano in a terminal to do quick and dirty files all the way up to full
configurations. It's handy, but keep in mind it handles plain text files and programming
files, things like MS Word documents will not open properly!
2. If a file is owned by root, it is not editable as a normal user. nano must be prefixed with
sudo in order to save changes. Otherwise, it will open in read-only mode.
3. nano newfile.whatever Nano creates a new file of the specified name and opens it for
editing.
4. nano existing_file Nano opens the existing file for editing.
5. From inside nano
1. Save file using the ctrl+o key combination, and either change the name or press
entier to keep the same name. This will save the file.
2. Exit nano by using ctrl+x key combination. If you have unsaved changes, it will ask
if you want to save.
mkdir -> Create directories
1. mkdir folder_name Creates the folder with the specified name
2. mkdir -p /path/to/folder/name Creates each folder as necessary. To create folder
/home/justin/newfolder/2ndfolder, and only /home/justin exists, using mkdir -p will make
both directories newfolder and 2ndfolder.
ps -> List processes
1. ps aux List all processes in detail running on the system, including user, Process ID (PID),
and name of process. Using this, one can view their process list and if necessary, kill
unnecessary or stalled processes.
kill / killall / xkill -> Kill offending processes.
1. kill PID PID is a number referencing the offending process. One should obtain the PID
from a command like ps aux. If a process refuses to die, one can alternatively specify kill -9

PID which should terminate the process by any means, even uncleanly or if it will mess up
the system.
2. killall program Killall kills *by name* all instances of said program. If there are for
example 3 firefox sessions open, killall firefox will do just that; kill all firefox sessions. kill
would simply take the specified PID of the offending firefox process you wish to kill, and
kill that one only.
3. xkill is a GUI way to click and kill windows. Typing in xkill should present a skull-andcrossbones icon, and the next window clicked on will be killed.
Pipes -> The most useful thing you will learn in *NIX. Redirecting output of a program to
anothers input.
1. Pipes are represented by the ' straight bar ' otherwise known as the ' | ' key.
2. It is a rarely used key in Windows, it is often found on the backslash key.
3. They are used to link commands together. Pipes take the output of one command and route
it to be used as input for a second command chained together.
4. Consult more online resources with information about pipes and their use as there are
volumes.
> and >> redirectors -> Send output to a file instead of the terminal.
1. > is used to *overwrite* currently existing files contents and replace with the output from
the new command.
2. >> is used to *append* information to currently existing files. This is useful for logging.
3. Example: ps aux > processes.log Sends the output of ps aux to the file processes.log for
viewing the command output in a text editor and overwrites the current contents of the file.
tee -> Send output to both a file and the terminal
1. tee is used in conjunction with a ' | ' in order to take the command output and send it
elsewhere. This is useful if there are errors which fly by the screen before you can read
them, this way whatever goes on the screen is also captured to a file.
2. Example: dmesg | tee boot.txt would run the command dmesg which shows the initial boot
info, and the ' | ' sends the output of dmesg to tee, which then does its job by sending it to
the terminal and to the log file boot.txt.
File Execution -> So you want to execute files or programs from the terminal? Make sure it's
marked executable. If not, see Quick Tip #4 below.
1. Need to execute a file in the current directory after it is marked executable? The ./ operator
can execute the file as a normal user provided you do not need root rights. ./ literally means
"in the current directory" so it does not work on files outside of the present directory.
2. Need to execute a file not in the current directory? You must pass the path to the proper
executing program. If it is a python program, it's python /path/to/file and if it is a shell file,
it is sh /path/to/file as an example. There are of course other programs, but these will be the
most common for beginners.

3. Need to execute a file with root rights because you received operation not permitted? Prefix
the command with sudo. Thus, from the above example, sudo python /path/to/file will
execute the script with root rights.
4. Need to execute a GUI program from the terminal? Simply type the program name (case
sensitive!) and it will launch. This will render the current terminal unusable. Closing the
terminal while the program is open will kill the program. A better way is to background the
program, using program_name & and then typing the word exit at the terminal to close it
and keep the process running.
5. Need to run a GUI program with root rights from the terminal? Prefix it with gksudo or
gksu and not sudo. Using sudo to launch GUI applications is a bad habit and should be
avoided.
6. Do not, do *not* use sudo simply because something receives "Operation not
permitted." Keep in mind what you are doing as you can absolutely *destroy* systems
by running commands in the wrong place with root rights. This point cannot be
emphasized enough. Make sure your files come from reputable sources.
Quick tips:
1. Lost yourself in a directory? Not sure where you are? Type pwd to print working directory.
2. Want to calculate your disk space quickly? df -h can give you a quick checkup.
3. Want to calculate the size of a folder or file quickly? du -cksh target_name can do exactly
that. Want to calculate the size of the current folder? du -cksh .
4. Need to mark a file executable? chmod +x filename can do that. Next time you see a file
you need to execute and it is not marked executable, now you know how to fix it.
5. Want to mount an iso like Daemon-Tools on Windows? Linux has this functionality built
in. Simply create a directory somewhere, say /home/justin/isomount, and issue the
command mount -o loop /path/to/myisofile.iso /home/justin/isomount and the contents
will be mounted inside that folder.
6. Run a command before, you need to re-run it, but you can't really remember what it was
exactly? Type history into the terminal and it will print out your command history. Want to
clear your history? history -c will wipe the information.

You might also like