Common Linux Ubuntu Commands Overview
Common Linux Ubuntu Commands Overview
pwd
Print working directory, i.e., display the name of my current directory on
the screen.
hostname
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.
date
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 command:
date 123123572000
To set the hardware (BIOS) clock from the system (Linux) clock, use the
command (as root) setclock
System Information
who
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.
Basic operations
cp file1 file2
or
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
Copy files
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 asked.
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.
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
Permissions
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 location.
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.
Permissions
examples:
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
Account Permissions
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
Pipe
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
Pipe
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
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
Example1
Find all the files whose name is tecmint.txt in a current working directory.
# find . -name tecmint.txt.
Find all php files in a directory.
Example 2:
# find . -type f -name "*.php"
./tecmint.php
./login.php
./index.php
Network
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
OR
ifdown eth0
How to Assign a IP Address to Network Interface
ifconfig eth0 172.16.25.125
Tcpdump Commands – A Network Sniffer Tool
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
print
ls List files
cp Copy files
mv Rename files
rm Delete files
ln Link files
cd Change directory
pwd Print current directory
name
mkdir Create directory
rmdir Delete directory
Printing