PresentationPDF Available

Common Linux Ubuntu Commands Overview



list of Common Linux Ubuntu Commands Overview
Common Linux Ubuntu Commands
Prepared by: Ameer Sameer Hamood
University of Babylon - Iraq
Information Technology - Information
System Information
Print working directory, i.e., display the name of my current
directory on the screen.
Print the name of the local host (the machine on which you are
working). Use netconf (as root) to change the name of the machine.
id username
Print user id (uid) and his/her group id (gid), effective id (if different
than the real id) and the supplementary groups.
Print or change the operating system date and time. E.g., I could
change the date and time to 2000-12-31 23:57 using this
date 123123572000
To set the hardware (BIOS) clock from the system (Linux) clock,
use the command (as root) setclock
Determine the users logged on the machine.
finger user_name
System info about a user. Try: finger root . displays the user's login
name, real name, terminal name and write status (as a ``*'' after the
terminal name if write permission is denied), idle time, login time,
office location .
history | more
Show the last (1000 or so) commands executed from the command
line on the current account. The "| more" causes the display to stop
after each screenful.
System Information
Basic operations
any_command --help |more
Display a brief help on a command (works with most commands). "--
help" works similar to DOS "/h" switch. The "more" pipe is needed if
the output is longer than one screen.
man topic
Display the contents of the system manual pages (help) on the
Info topic
information pages, which are generally more in-depth
than man pages.
List Command
ls - Short listing of directory contents
-a list hidden files
-d list the name of the current directory
-F show directories with a trailing '/'
executable files with a trailing '*'
-g show group ownership of file in long listing
-i print the inode number of each file
-l long listing giving details about files and directories
-R list all subdirectories encountered
-t sort by time modified instead of name
Copy files
cp file1 file2
cp myfile yourfile
Copy the files "myfile" to the file "yourfile" in the current working
directory. This command will create the file "yourfile" if it doesn't
exist. It will normally overwrite it without warning if it exists.
cp -i myfile yourfile
With the "-i" option, if the file "yourfile" exists, you will be prompted
before it is overwritten.
mv source destination
Move or rename files. The same command is used for moving and
renaming files and directories. Ex: mv testdir newnamedir
rm files
Remove (delete) files. You must own the file in order to be able to
remove it. On many systems, you will be asked or confirmation of
deleation, if you don't want this, use the "-f" (=force) option, e.g., rm
-f * will remove all files in my current working directory, no questions
mkdir directory
Make a new directory.
rmdir directory
Remove an empty directory.
rm -r files
(recursive remove) Remove files, directories, and their
subdirectories. Careful with this command as root--you can easily
remove all files on the system with such a command executed on
the top of your directory tree, and there is no undelete in Linux (yet).
But if you really wanted to do it (reconsider), here is how (as
root): rm -rf /*
Copy files
cat filename
View the content of a text file called "filename"
find / -name filename
Find the file called "filename" on your file system starting the search
from the root directory "/". The "filename" may contain wildcards
(*,?).ex: find / -name "file.text"
locate filename
Find the file name of which contains the string "filename". Easier
and faster than the previous command but depends on a database
that normally rebuilds at night.
Copy files
Basic Administration Commands
adduser user_name
Create a new account (you must be root). E.g., adduser
barbara Don't forget to set up the password for the new user in the
next step. The user home directory is /home/user_name.
useradd user_name
The same as the command " adduser user_name ".
userdel user_name
Remove an account (you must be a root). The user's home directory
and the undelivered mail must be dealt with separately (manually
because you have to decide what to do with the files).
groupadd group_name
Create a new group on your system. Non-essential but can be
handy even on a home machine with a small number of users.
passwd user_name
Change the password on your current account. If you are root,
you can change the password for any user
using: passwd user_name
File Permissions
chmod perm filename
chmod command sets the permission of a file or folder. chmod
command uses three digit code as an argument and the file or folder
In the example,
7 – Owner(current user)
5 – Group(set by owner)
4 – anyone else
The fundamental concept:
Execute is 1, Write is 2 and Read is 4.
Sum of these basic ones makes combination of permissions:
0 – no permission, this person cannot read, write or execute
1 – execute only
2 – write only
3 – execute and write only (1 + 2)
4 – read only
5 – execute and read only (1 + 4)
6 – write and read only (2 + 4)
7 – execute, write and read (1 + 2 + 4)
Account Permissions
sudo useradd -m -s /bin/bash user_Name
explain: -s User's login shell (default /bin/bash)
-m Create the home directory
-M Do not create the home directory
2- sudo passwd user_Name
3- unlock
sudo passwd -u user_Name
4- Add Full Name
sudo usermod -c "Full Name" user_Name
5- add group
sudo groupadd group_Name
add user to group
sudo usermod -G group_Name user_Name
6- Delete a user
userdel -r user_Name
id Print user and group id's
Account Permissions
The pipe allows us to change this paradigm, whereby the output of
one program becomes the input of another program.
Example1 :
I would do that by using the | character — which is called,
appropriately enough, the pipe — as follows:
$ ls -l | less
This tells BASH to do the following:
1-Execute the ls command, with the parameter -l as input
2-Take the results of executing that command — the output —
and pass them as input to the less command
3-Send the output of the less command to the monitor as usual
Example2 :
$ ls -l | grep 'init' | less
List all of the files, using the -l option
Search the results of that file listing for the string init
Send the results of that search to less
Redirection is similar to pipes except using files rather than another
program. The standard output for a program is the screen. Using the
> (greater than) symbol the output of a program can be sent to a file.
Here is a directory listing of /dev again but this time redirected to a
file called listing.txt
ls -la > listing.txt
There won’t be anything displayed on the terminal as everything
was sent to the file. You can take a look at the file using the cat
command (which can be piped into more) or for convenience you
can just use the more command on its own:
more listing.txt
If listing.txt had already existed, it will be overwritten. But you can
append to an existing file using >> like this:
ls -la /home > listing.txt
ls -la /dev >> listing.txt
Search Command
Grep command
How do I use grep with other commands?
The syntax is:
command | grep 'search-pattern'
command1 | command2 | grep 'search-pattern'
In this example, run ls command and search for the string/pattern
called resume.pdf:
ls | grep resume.pdf
ls -l | grep resumd.pdf
ls -l *.mov | grep 'birthday'
ls -l *.mov | grep -i 'birthday'
Find Command
The Linux Find Command is one of the most important and much
used command in Linux systems. Find command used to search
and locate list of files and directories based on conditions you
specify for files that match the arguments. Find can be used in
variety of conditions like you can find files by permissions, users,
groups, file type, date, size and other possible criteria
Find all the files whose name is tecmint.txt in a current working
# find . -name tecmint.txt.
Find all php files in a directory.
Example 2:
# find . -type f -name "*.php"
ping Test a network connection
ping user_Name
Nmap ("Network Mapper") is an open source tool for network
exploration and security auditing.
sudo apt-get install nmap
To quickly identify all available Ethernet interfaces, you can use the
ifconfig command as shown below.
ifconfig -a | grep eth
eth0 Link encap:Ethernet HWaddr 00:15:c5:4a:16:5a
ethtool is a program that displays and changes Ethernet card
settings such as auto-negotiation, port speed, duplex mode, and
Wake-on-LAN. It is not installed by default, but is available for
installation in the repositories.
sudo apt-get install ethtool
The following is an example of how to view supported features and
configured settings of an Ethernet interface.
sudo ethtool eth0
To temporarily configure an IP address, you can use the ifconfig
command in the following manner. Just modify the IP address and
subnet mask to match your network requirements.
sudo ifconfig eth0 netmask
To verify the IP address configuration of eth0, you can use the
ifconfig command in the following manner.
ifconfig eth0
To verify your default gateway configuration, you can use the route
command in the following manner.
route –n
Display Information of All Network Interfaces
ifconfig eth0
To verify your default gateway configuration, you can use the route
command in the following manner.
route –n
Display Information of All Network Interfaces
ifconfig –a
How to Disable an Network Interface
ifconfig eth0 down
ifdown eth0
How to Assign a IP Address to Network Interface
ifconfig eth0
Tcpdump Commands – A Network Sniffer Tool
tcpdump is a most powerful and widely used command-line
packets sniffer or package analyzer tool which is used to
capture or filter TCP/IP packets that received or transferred over
a network on a specific interface.
How to Install tcpdump in Linux
Many of Linux distributions already shipped with tcpdump tool,
if in case you don’t have it on systems, you can install it using
following Yum command.
# yum install tcpdump
1. Capture Packets from Specific Interface
tcpdump -i eth0
2. Capture Only N Number of Packets
tcpdump -c 5 -i eth0
3. Display Available Interfaces
tcpdump -D
4.Capture IP address Packets
tcpdump -n -i eth0
5. Capture only TCP Packets.
tcpdump -i eth0 tcp
6. Capture Packets from source IP
tcpdump -i eth0 src
7. Capture Packets from destination IP
tcpdump -i eth0 dst
Tcpdump Commands – A Network Sniffer Tool
install , remove App in linux
1- install :
sudo apt-get install Package_Name
2- remove :
apt-get remove package_Name
To remove any unused packages, use the “autoremove” command,
as shown in the following command.
sudo apt-get autoremove
You can combine the two commands for removing a program and
removing dependencies that are no longer being used into one, as
shown below (again, two dashes before “auto-remove”).
sudo apt-get purge --auto-remove gimp
If you’re short on space, you can use the “clean” command to
remove downloaded archive files, as shown below.
sudo apt-get clean
echo Display message on screen •
File Compression
gzip Compress files
(GNU Zip)
compress Compress files (Unix)
bzip2 Compress files (BZip2)
zip Compress files
(Windows Zip)
Disks and Filesystems
df Show free disk space
mount Make a disk accessible
fsck Check a disk for errors
sync Flush disk caches
Backups and Remote Storage
mt Control a tape drive
dump Back up a disk
restore Restore a dump
tar Read/write tape archives
cdrecord Burn a CD
rsync Mirror a set of files
File Properties
stat Display file attributes
wc Count bytes/words/lines
du Measure disk usage
file Identify file types
touch Change file timestamps
chown Change file owner
chgrp Change file group
chmod Change file protections
chattr Change advanced file
lsattr List advanced file
File Viewing
cat View files
less Page through files
head View file beginning
tail View file ending
nl Number lines
od View binary data
xxd View binary data
gv View Postscript/PDF files
xdvi View TeX DVI files
File Location
find Locate files
slocate Locate files via index
which Locate commands
whereis Locate standard files
File/Directory Basics
ls List files
cp Copy files
mv Rename files
rm Delete files
ln Link files
cd Change directory
pwd Print current directory
mkdir Create directory
rmdir Delete directory
lpr Print files
lpq View print queue
lprm Remove print jobs
Spelling Operations
look Look up spelling
aspell Check spelling
spell Check spelling in batch
ps List all processes
w List users’ processes
uptime View the system load
top Monitor processes
xload Monitor system load
free Display free memory
kill Terminate processes
nice Set process priorities
renice Change process priorities
Scheduling Jobs
sleep Wait for some time
watch Run programs at set
at Schedule a job
crontab Schedule repeated jobs
uname Print system information
hostname Print the system’s
ifconfig Set/display network
host Look up DNS
whois Look up domain
ping Check if host is reachable
traceroute View network path to
a host
Audio and Video
grip Play CDs and rip MP3s
xmms Play audio files
cdparanoia Rip audio
audacity Edit audio
xcdroast Burn CDs
ResearchGate has not been able to resolve any citations for this publication.
ResearchGate has not been able to resolve any references for this publication.