Linux Commands
Linux Commands
Linux Commands
I get it.
You're new to the Linux Command Line and truth be told, you might be a little intimidated. Coming from the
comfort of a PC or Mac desktop, the Linux Command Line (CLI) looks nothing like what you normally use.
The Linux CLI is dark, it's secretive, it's bare bones minimal and it's anything but friendly to newcomers. And
yet, the Linux CLI is highly useful, essential to using your Linux box or virtual machine and can, if done right,
provide you with more insight and practical use than the Windows or Mac desktop ever could.
For those reasons, from someone who was also once a Linux newb, I present the top ten Linux CLI commands
you need to master for basic Linux CLI comprehension.
This list will not make your a Linux System Admin however it will get you on your way with your foot in the
ocean.
Before my top ten Linux CLI list, I want to preface this countdown by stating the commands presented are
being presented to give you a working knowledge of how to get around your Linux terminal from the shell. This
list is meant to serve as an introduction to basic yet highly vital Linux CLI commands.
There are a ton of other commands - more sophisticated commands - which you will one day learn. But for
now, like learning to add before you learn to multiply, this list will provide you with your Linux CLI
command foundation.
At the end of the list, some vital information you need to use the Linux CLI.
1. ls
The ls command - the list command - functions in the Linux terminal to show all of the major directories filed
under a given file system. For example, the command:
ls /applications
...will show the user all of the folders stored in the overall applications folder.
2. cd
The cd command - change directory - will allow the user to change between file directories. As the name
command name suggest, you would use the cd command to circulate between two different directories. For
example, if you wanted to change from the home directory to the Arora directory, you would input the following
command:
cd/arora/applications
As you might have noted, the path name listed lists in reverse order. Logically cd/arora/applications reads
change to the arora directory which is stored in the applications directory. All Linux commands follow a logical
path.
3. mv
The mv command - move - allows a user to move a file to another folder or directory. Just like dragging a file
located on a PC desktop to a folder stored within the "Documents" folder, the mv command functions in the
same manner. An example of the mv command is:
mv/arora/applications/majorapps /arora/applications/minorapps
4. man
The man command - the manual command - is used to show the manual of the inputted command. Just like a
film on the nature of film, the man command is the meta command of the Linux CLI. Inputting the man
command will show you all information about the command you are using. An example:
man cd
The inputting command will show the manual or all relevant information for the change directory command.
5. mkdir
The mkdir - make directory - command allows the user to make a new directory. Just like making a new
directory within a PC or Mac desktop environment, the mkdir command makes new directories in a Linux
environment. An example of the mkdir command
mkdir testdirectory
6. rmdir
The rmdir - remove directory - command allows the user to remove an existing command using the Linux CLI.
An example of the rmdir command:
rmdir testdirectory
The example command removed the directory "testdirectory".
It should be noted: both the mkdir and rmdir commands make and remove directories. They do not
make files and they will also not remove a directory which has files in it. The mkdir will make an empty
directory and the rmdir command will remove an empty directory.
7. touch
The touch command - a.k.a. the make file command - allows users to make files using the Linux CLI. Just as
the mkdir command makes directories, the touch command makes files. Just as you would make a .doc or a
.txt using a PC desktop, the touch command makes empty files. An example of the touch command:
touch testfile.txt
The example touch command effectively created the file testfile.txt. As noted by the extension, the file created
is a .txt or text file. To equate, a .txt file in Linux is akin to a .txt notebook file within a Windows or Mac OS.
8. rm
The rm command - remove - like the rmdir command is meant to remove files from your Linux OS. Whereas
the rmdir command will remove directories and files held within, the rm command will delete created files. An
example of the rm command:
rm testfile.txt
The aforementioned command removed testfile.txt. Interestingly, whereas the rmdir command will only delete
an empty directory, the rm command will remove both files and directories with files in it. This said, the rm
command carries more weight than the rmdir command and should be used with more specificity.
9. locate
The locate - a.k.a. find - command is meant to find a file within the Linux OS. If you don't know the name of a
certain file or you aren't sure where the file is saved and stored, the locate command comes in handy. A locate
command example:
locate -i *red*house**city*
The stated command will locate an file with the a file name containing "Red", "House" and "City". A note on the
input: the use of "-i" tells the system to search for a file unspecific of capitalization (Linux functions in lower
case). The use of the asterik "*" signifies searching for a wildcard. A wildcard tells the system to pull any and all
files containing the search criteria.
By specifying -i with wildcards, the locate CLI command will pull back all files containing your search criteria
effectivley casting the widest search net the system will allow.
10. clear
The clear command does exactly what it says. When your Linux CLI gets all mucked up with various readouts
and information, the clear command clears the screen and wipes the board clean. Using the clear command
will take the user back to the start prompt of whatever directory you are currently operating in. To use the clear
command simply type clear.
This is not a comprehensive list by any means, but this should give you a jumpstart on
some of the common Linux commands. Bookmark this article for your future reference.
Did I miss any frequently used Linux commands? Leave a comment and let me know.
More tar examples: The Ultimate Tar Command Tutorial with 10 Practical Examples
Print the matched line, along with the 3 lines after it.
$ grep -r "ramesh" *
More grep examples: Get a Grip on the Grep! – 15 Practical Grep Command Examples
# find ~ -empty
More find examples: Mommy, I found it! — 15 Practical Linux Find Command Examples
$ ssh -V
Print all lines from /etc/passwd that has the same uid and gid
More awk examples: 8 Powerful Awk Built-in Variables – FS, OFS, RS, ORS, NR, NF,
FILENAME, FNR
$ vim -R /etc/passwd
2c2,3
More diff examples: Top 4 File Difference Tools on UNIX / Linux – Diff, Colordiff,
Wdiff, Vimdiff
$ sort names.txt
$ sort -r names.txt
declare -x ORACLE_BASE="/u01/app/oracle"
declare -x ORACLE_HOME="/u01/app/oracle/product/10.2.0"
declare -x ORACLE_SID="med"
declare -x ORACLE_TERM="xterm"
$ export ORACLE_HOME=/u01/app/oracle/product/10.2.0
$ ls -lh
-rw-r----- 1 ramesh team-dev 8.9M Jun 12 15:27 arch-linux.txt.gz
Order Files Based on Last Modified Time (In Reverse Order) Using ls -ltr
$ ls -ltr
$ ls -F
$ gzip test.txt
$ gzip -d test.txt.gz
Display compression ratio of the compressed file using gzip -l
$ gzip -l *.gz
$ bzip2 test.txt
bzip2 -d test.txt.bz2
More bzip2 examples: BZ is Eazy! bzip2, bzgrep, bzcmp, bzdiff, bzcat, bzless, bzmore
examples
$ unzip test.zip
$ unzip -l jasper.zip
Archive: jasper.zip
# shutdown -h now
# shutdown -h +10
# shutdown -r now
To view the file names located on the remote server before downloading, mls ftp
command as shown below.
/ftptest/features.html
/ftptest/index.html
/ftptest/othertools.html
/ftptest/samplereport.html
/ftptest/usage.html
# crontab -u john -l
*/10 * * * * /home/ramesh/check-disk-space
service --status-all
Restart a service.
While there are lot of arguments that could be passed to a ps command, following are
some of the common ones.
$ ps -ef | more
To view current running processes in a tree structure. H option stands for process
hierarchy.
$ ps -efH | more
23. free command examples
This command is used to display the free, used, swap memory available in the system.
$ free
If you want to quickly check how many GB of RAM your system has use the -g option. -b
option displays in bytes, -k in kilo bytes, -m in mega bytes.
$ free -g
Mem: 3 1 1 0 0 0
-/+ buffers/cache: 0 2
Swap: 3 0 3
If you want to see a total memory ( including the swap), use the -t switch, which will
display a total line as shown below.
ramesh@ramesh-laptop:~$ free -t
Select sort field via field letter, type any other key to return
........
To displays only the processes that belong to a particular user use -u option. The
following will show only the top processes that belongs to oracle user.
$ top -u oracle
More top examples: Can You Top This? 15 Practical Linux Top Command Examples
df -h displays output in human readable form. i.e size will be displayed in GB’s.
ramesh@ramesh-laptop:~$ df -h
ramesh@ramesh-laptop:~$ df -T
$ kill -9 7243
More kill examples: 4 Ways to Kill a Process – kill, killall, pkill, xkill
$ rm -i filename.txt
It is very useful while giving shell metacharacters in the file name argument.
Print the filename and get confirmation before removing the file.
$ rm -i file*
Following example recursively removes all files and directories under the example
directory. This also removes the example directory itself.
$ rm -r example
$ cp -p file1 file2
Copy file1 to file2. if file2 exists prompt for confirmation before overwritting it.
$ cp -i file1 file2
$ mv -i file1 file2
Note: mv -f is just the opposite, which will overwrite file2 without prompting.
mv -v will print what is happening during file rename, which is useful while specifying
shell metacharacters in the file name argument.
$ mv -v file1 file2
While displaying the file, following cat -n command will prepend the line number to
each line of the output.
$ cat -n /etc/logrotate.conf
1 /var/log/btmp {
2 missingok
3 monthly
6 }
# mkdir /u01
You can also add this to the fstab for automatic mounting. i.e Anytime system is
restarted, the filesystem will be mounted.
Give full access to user and group (i.e read, write and execute ) on a specific file.
Revoke all access for the group (i.e read, write and execute ) on a specific file.
Apply the file permissions recursively to all the files in the sub-directories.
$ chmod -R ug+rwx file.txt
To change owner to oracle and group to db on a file. i.e Change both owner and group at
the same time.
$ passwd
Super user can use passwd command to reset others password. This will not prompt for
current password of the user.
# passwd USERNAME
Remove password for a specific user. Root user can disable password for a specific user.
Once the password is disabled, the user can login without entering the password.
# passwd -d USERNAME
35. mkdir command examples
Following example creates a directory called temp under your home directory.
$ mkdir ~/temp
Create nested directories using one mkdir command. If any of these directories exist
already, it will not display any error. If any of these directories doesn’t exist, it will
create them.
$ mkdir -p dir1/dir2/dir3/dir4/
$ ifconfig -a
Start or stop a specific interface using up and down command as shown below.
$ ifconfig eth0 up
Linux john-laptop 2.6.32-24-generic #41-Ubuntu SMP Thu Aug 19 01:12:52 UTC 2010 i686
GNU/Linux
$ whereis ls
When you want to search an executable from a path other than the whereis default path,
you can use -B option and give path as argument to it. This searches for the executable
lsmk in the /tmp directory, and displays it, if it is available.
lsmk: /tmp/lsmk
$ whatis ls
$ whatis ifconfig
The example below shows all files in the system that contains the word crontab in it.
$ locate crontab
/etc/anacrontab
/etc/crontab
/usr/bin/crontab
/usr/share/doc/cron/examples/crontab2english.pl.gz
/usr/share/man/man1/crontab.1.gz
/usr/share/man/man5/anacrontab.5.gz
/usr/share/man/man5/crontab.5.gz
/usr/share/vim/vim72/syntax/crontab.vim
$ man crontab
When a man page for a command is located under more than one section, you can view
the man page for that command from a specific section as shown below.
$ whatis crontab
$ man 5 crontab
$ tail filename.txt
$ tail -n N filename.txt
View the content of the file in real time using tail -f. This is useful to view the log files,
that keeps growing. The command can be terminated using CTRL-C.
$ tail -f log-file
More tail examples: 3 Methods To View tail -f output of Multiple Log Files in One
Terminal
$ less huge-log-file.log
One you open a file using less command, following two keys are very helpful.
$ su - USERNAME
Execute a single command from a different account name. In the following example,
john can execute the ls command as raj username. Once the command is executed, it
will come back to john’s account.
[john@dev-server]$
Login to a specified user account, and execute the specified shell instead of the default
shell.
$ su -s 'SHELLNAME' USERNAME
$ mysql -u root -p
If you want to specify the mysql root password in the command line itself, enter it
immediately after -p (without any space).
$ ping -c 5 gmail.com
# hwclock –systohc
$ wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz
1. Command: ls
The command “ls” stands for (List Directory Contents), List the contents of the
folder, be it file or folder, from which it runs.
root@tecmint:~# ls
Android-Games Music
Pictures Public
Desktop Tecmint.com
Documents TecMint-Sync
Downloads Templates
The command “ls -l” list the content of folder, in long listing fashion.
root@tecmint:~# ls -l
total 40588
Command “ls -a“, list the content of folder, including hidden files starting with ‘.’.
root@tecmint:~# ls -a
root@tecmint:~# lsblk
The “lsblk -l” command list block devices in ‘list‘ structure (not tree like
fashion).
root@tecmint:~# lsblk -l
Note: lsblk is very useful and easiest way to know the name of New Usb
Device you just plugged in, especially when you have to deal with disk/blocks
in terminal.
3. Command: md5sum
The “md5sum” stands for (Compute and Check MD5 Message Digest), md5
checksum (commonly called hash) is used to match or verify integrity of files
that may have changed as a result of a faulty file transfer, a disk error or non-
malicious interference.
47790ed345a7b7970fc1f2ac50c97002 teamviewer_linux.deb
Note: The user can match the generated md5sum with the one provided
officially. Md5sum is considered less secure than sha1sum, which we will
discuss later.
4. Command: dd
Command “dd” stands for (Convert and Copy a file), Can be used to convert
and copy a file and most of the times is used to copy a iso file (or any other
file) to a usb device (or any other location), thus can be used to make a
‘Bootlable‘ Usb Stick.
Note: In the above example the usb device is supposed to be sdb1 (You
should Verify it using command lsblk, otherwise you will overwrite your disk
and OS), use name of disk very Cautiously!!!.
dd command takes some time ranging from a few seconds to several minutes
in execution, depending on the size and type of file and read and write speed
of Usb stick.
5. Command: uname
The “uname” command stands for (Unix Name), print detailed information about
the machine name, Operating System and Kernel.
root@tecmint:~# uname -a
Linux tecmint 3.8.0-19-generic #30-Ubuntu SMP Wed May 1 16:36:13 UTC 2013 i686 i686 i686 GNU/Linux
6. Command: history
The “history” command stands for History (Event) Record, it prints the history of
long list of executed commands in terminal.
root@tecmint:~# history
10 pwd
12 cd /usr/share/unity/icons/
13 cd /usr/share/unity
Note: Pressing “Ctrl + R” and then search for already executed commands
which lets your command to be completed with auto completion feature.
(reverse-i-search)`if': ifconfig
7. Command: sudo
The “sudo” (super user do) command allows a permitted user to execute a
command as the superuser or another user, as specified by the security policy
in the sudoers list.
8. Command: mkdir
The “mkdir” (Make directory) command create a new directory with name path.
However is the directory already exists, it will return an error message “cannot
create folder, folder already exists”.
Note: Directory can only be created inside the folder, in which the user has
write permission. mkdir: cannot create directory `tecmint‘: File exists
(Don’t confuse with file in the above output, you might remember what i said
at the beginning – In Linux every file, folder, drive, command, scripts are
treated as file).
9. Command: touch
The “touch” command stands for (Update the access and modification times of
each FILE to the current time). touch command creates the file, only if it
doesn’t exist. If the file already exists it will update the timestamp and not the
contents of the file.
Note: touch can be used to create file under directory, on which the user has
write permission, only if the file don’t exist there.
10. Command: chmod
The Linux “chmod” command stands for (change file mode bits). chmod changes
the file mode (permission) of each given file, folder, script, etc.. according to
mode asked for.
There exist 3 types of permission on a file (folder or anything but to keep
things simple we will be using file).
Read (r)=4
Write(w)=2
Execute(x)=1
So if you want to give only read permission on a file it will be assigned a value
of ‘4‘, for write permission only, a value of ‘2‘ and for execute permission only,
a value of ‘1‘ is to be given. For read and write permission 4+2 = ‘6‘ is to be
given, ans so on.
Now permission need to be set for 3 kinds of user and usergroup. The first is
owner, then usergroup and finally world.
rwxr-x--x abc.sh
root@tecmint:~# ls -l
java-wrappers
Suggested packages:
Note: The above commands results into system-wide changes and hence
requires root password (Check ‘#‘ and not ‘$’ as prompt). Apt is considered
more advanced and intelligent as compared to yum command.
As the name suggest, apt-cache search for package containing sub
package mpalyer. apt-get install, update all the packages, that are already
installed, to the newest one.
Read more about apt-get and apt-cache commands at 25 APT-GET and APT-
CACHE Commands
13. Command: tar
The “tar” command is a Tape Archive is useful in creation of archive, in a
number of file format and their extraction.
root@tecmint:~# tar -zxvf abc.tar.gz (Remember 'z' for .tar.gz)
root@tecmint:~# tar -jxvf abc.tar.bz2 (Remember 'j' for .tar.bz2)
root@tecmint:~# tar -cvf archieve.tar.gz(.bz2) /path/to/folder/abc
Note: A ‘tar.gz‘ means gzipped. ‘tar.bz2‘ is compressed with bzip which uses a
better but slower compression method.
Read more about “tar command” examples at 18 Tar Command Examples
14. Command: cal
The “cal” (Calendar), it is used to displays calendar of the present month or any
other month of any year that is advancing or passed.
root@tecmint:~# cal
May 2013
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
July 2145
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Note: You need not to turn the calendar of 50 years back, neither you need to
make complex mathematical calculation to know what day you were worn or
your coming birthday will fall on which day.
15. Command: date
The “date” (Date) command print the current date and time on the standard
output, and can further be set.
root@tecmint:~# date
Note: This Command will be very use-full in scripting, time and date based
scripting, to be more perfect. Moreover changing date and time using terminal
will make you feel GEEK!!!. (Obviously you need to be root to perform this
operation, as it is a system wide change).
16. Command: cat
The “cat” stands for (Concatenation). Concatenate (join) two or more plain file
and/or print contents of a file on standard output.
....
...
Note: “>>” and “>” are called append symbol. They are used to append the
output to a file and not on standard output. “>” symbol will delete a file already
existed and create a new file hence for security reason it is advised to use
“>>” that will write the output without overwriting or deleting the file.
Before Proceeding further, I must let you know about wildcards (you would be
aware of wildcard entry, in most of the Television shows) Wildcards are a shell
feature that makes the command line much more powerful than any GUI file
managers. You see, if you want to select a big group of files in a graphical file
manager, you usually have to select them with your mouse. This may seem
simple, but in some cases it can be very frustrating.
For example, suppose you have a directory with a huge amount of all kinds of
files and subdirectories, and you decide to move all the HTML files, that have
the word “Linux” somewhere in the middle of their names, from that big
directory into another directory. What’s a simple way to do this? If the
directory contains a huge amount of differently named HTML files, your task is
everything but simple!
In the Linux CLI that task is just as simple to perform as moving only one
HTML file, and it’s so easy because of the shell wildcards. These are special
characters that allow you to select file names that match certain patterns of
characters. This helps you to select even a big group of files with typing just a
few characters, and in most cases it’s easier than selecting the files with a
mouse.
Wildcard Matches
* zero or more characters
? exactly one character
[abcde] exactly one character listed
[a-e] exactly one character in the given range
[!abcde] any character that is not listed
[!a-e] any character that is not in the given range
{debian,linux} exactly one entire word in the options given
! is called not symbol, and the reverse of string attached with ‘!’ is true.
Read more examples of Linux “cat command” at 13 Cat Command Examples in
Linux
17. Command: cp
The “copy” stands for (Copy), it copies a file from one location to another
location.
root@tecmint:~# pwd
/home/user/Desktop
root@tecmint:~# cd /home/user/Desktop
server@localhost:~$ pwd
/home/user/Desktop
SERVICES / PROGRAMS SOC 1,2,3
Amazon CloudFront ✓
Amazon Cognito ✓
Amazon Connect ✓
Amazon DynamoDB ✓
Amazon ElastiCache ✓
Amazon Glacier ✓
Amazon Inspector ✓
Amazon Redshift ✓
Amazon RDS ✓
Amazon Route 53 ✓
Amazon SimpleDB ✓
Amazon WorkMail ✓
Amazon WorkSpaces ✓
Auto Scaling ✓
AWS CloudFormation ✓
AWS CloudHSM ✓
AWS CloudTrail ✓
AWS Lambda ✓
AWS Lambda@Edge ✓
AWS Shield ✓
VM Import/Export ✓
1. Command: ls
The command “ls” stands for (List Directory Contents), List the contents of the
folder, be it file or folder, from which it runs.
root@tecmint:~# ls
Android-Games Music
Pictures Public
Desktop Tecmint.com
Documents TecMint-Sync
Downloads Templates
The command “ls -l” list the content of folder, in long listing fashion.
root@tecmint:~# ls -l
total 40588
Command “ls -a“, list the content of folder, including hidden files starting with ‘.’.
root@tecmint:~# ls -a
root@tecmint:~# lsblk
root@tecmint:~# lsblk -l
Note: lsblk is very useful and easiest way to know the name of New Usb
Device you just plugged in, especially when you have to deal with disk/blocks
in terminal.
3. Command: md5sum
The “md5sum” stands for (Compute and Check MD5 Message Digest), md5
checksum (commonly called hash) is used to match or verify integrity of files
that may have changed as a result of a faulty file transfer, a disk error or non-
malicious interference.
47790ed345a7b7970fc1f2ac50c97002 teamviewer_linux.deb
Note: The user can match the generated md5sum with the one provided
officially. Md5sum is considered less secure than sha1sum, which we will
discuss later.
4. Command: dd
Command “dd” stands for (Convert and Copy a file), Can be used to convert
and copy a file and most of the times is used to copy a iso file (or any other
file) to a usb device (or any other location), thus can be used to make a
‘Bootlable‘ Usb Stick.
Note: In the above example the usb device is supposed to be sdb1 (You
should Verify it using command lsblk, otherwise you will overwrite your disk
and OS), use name of disk very Cautiously!!!.
dd command takes some time ranging from a few seconds to several minutes
in execution, depending on the size and type of file and read and write speed
of Usb stick.
5. Command: uname
The “uname” command stands for (Unix Name), print detailed information about
the machine name, Operating System and Kernel.
root@tecmint:~# uname -a
Linux tecmint 3.8.0-19-generic #30-Ubuntu SMP Wed May 1 16:36:13 UTC 2013 i686 i686 i686 GNU/Linux
root@tecmint:~# history
10 pwd
12 cd /usr/share/unity/icons/
13 cd /usr/share/unity
Note: Pressing “Ctrl + R” and then search for already executed commands
which lets your command to be completed with auto completion feature.
(reverse-i-search)`if': ifconfig
7. Command: sudo
The “sudo” (super user do) command allows a permitted user to execute a
command as the superuser or another user, as specified by the security policy
in the sudoers list.
“To err is human, but to really foul up everything, you need root password.”
8. Command: mkdir
The “mkdir” (Make directory) command create a new directory with name path.
However is the directory already exists, it will return an error message “cannot
create folder, folder already exists”.
Note: Directory can only be created inside the folder, in which the user has
write permission. mkdir: cannot create directory `tecmint‘: File exists
(Don’t confuse with file in the above output, you might remember what i said
at the beginning – In Linux every file, folder, drive, command, scripts are
treated as file).
9. Command: touch
The “touch” command stands for (Update the access and modification times of
each FILE to the current time). touch command creates the file, only if it
doesn’t exist. If the file already exists it will update the timestamp and not the
contents of the file.
Note: touch can be used to create file under directory, on which the user has
write permission, only if the file don’t exist there.
10. Command: chmod
The Linux “chmod” command stands for (change file mode bits). chmod changes
the file mode (permission) of each given file, folder, script, etc.. according to
mode asked for.
There exist 3 types of permission on a file (folder or anything but to keep
things simple we will be using file).
Read (r)=4
Write(w)=2
Execute(x)=1
So if you want to give only read permission on a file it will be assigned a value
of ‘4‘, for write permission only, a value of ‘2‘ and for execute permission only,
a value of ‘1‘ is to be given. For read and write permission 4+2 = ‘6‘ is to be
given, ans so on.
Now permission need to be set for 3 kinds of user and usergroup. The first is
owner, then usergroup and finally world.
rwxr-x--x abc.sh
Here the root’s permission is rwx (read, write and execute).
usergroup to which it belongs, is r-x (read and execute only, no write
permission) and
for world is –x (only execute).
To change its permission and provide read, write and execute permission to
owner, group and world.
Note: one of the most important command useful for sysadmin and user both.
On a multi-user environment or on a server, this command comes to rescue,
setting wrong permission will either makes a file inaccessible or provide
unauthorized access to someone.
root@tecmint:~# ls -l
java-wrappers
Suggested packages:
Note: The above commands results into system-wide changes and hence
requires root password (Check ‘#‘ and not ‘$’ as prompt). Apt is considered
more advanced and intelligent as compared to yum command.
As the name suggest, apt-cache search for package containing sub
package mpalyer. apt-get install, update all the packages, that are already
installed, to the newest one.
Read more about apt-get and apt-cache commands at 25 APT-GET and APT-
CACHE Commands
13. Command: tar
The “tar” command is a Tape Archive is useful in creation of archive, in a
number of file format and their extraction.
root@tecmint:~# tar -zxvf abc.tar.gz (Remember 'z' for .tar.gz)
root@tecmint:~# tar -jxvf abc.tar.bz2 (Remember 'j' for .tar.bz2)
root@tecmint:~# tar -cvf archieve.tar.gz(.bz2) /path/to/folder/abc
Note: A ‘tar.gz‘ means gzipped. ‘tar.bz2‘ is compressed with bzip which uses a
better but slower compression method.
Read more about “tar command” examples at 18 Tar Command Examples
14. Command: cal
The “cal” (Calendar), it is used to displays calendar of the present month or any
other month of any year that is advancing or passed.
root@tecmint:~# cal
May 2013
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
February 1835
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
July 2145
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Note: You need not to turn the calendar of 50 years back, neither you need to
make complex mathematical calculation to know what day you were worn or
your coming birthday will fall on which day.
15. Command: date
The “date” (Date) command print the current date and time on the standard
output, and can further be set.
root@tecmint:~# date
Note: This Command will be very use-full in scripting, time and date based
scripting, to be more perfect. Moreover changing date and time using terminal
will make you feel GEEK!!!. (Obviously you need to be root to perform this
operation, as it is a system wide change).
16. Command: cat
The “cat” stands for (Concatenation). Concatenate (join) two or more plain file
and/or print contents of a file on standard output.
root@tecmint:~# cat a.txt b.txt c.txt d.txt >> abcd.txt
....
...
Note: “>>” and “>” are called append symbol. They are used to append the
output to a file and not on standard output. “>” symbol will delete a file already
existed and create a new file hence for security reason it is advised to use
“>>” that will write the output without overwriting or deleting the file.
Before Proceeding further, I must let you know about wildcards (you would be
aware of wildcard entry, in most of the Television shows) Wildcards are a shell
feature that makes the command line much more powerful than any GUI file
managers. You see, if you want to select a big group of files in a graphical file
manager, you usually have to select them with your mouse. This may seem
simple, but in some cases it can be very frustrating.
For example, suppose you have a directory with a huge amount of all kinds of
files and subdirectories, and you decide to move all the HTML files, that have
the word “Linux” somewhere in the middle of their names, from that big
directory into another directory. What’s a simple way to do this? If the
directory contains a huge amount of differently named HTML files, your task is
everything but simple!
In the Linux CLI that task is just as simple to perform as moving only one
HTML file, and it’s so easy because of the shell wildcards. These are special
characters that allow you to select file names that match certain patterns of
characters. This helps you to select even a big group of files with typing just a
few characters, and in most cases it’s easier than selecting the files with a
mouse.
Wildcard Matches
* zero or more characters
? exactly one character
[abcde] exactly one character listed
[a-e] exactly one character in the given range
[!abcde] any character that is not listed
[!a-e] any character that is not in the given range
{debian,linux} exactly one entire word in the options given
! is called not symbol, and the reverse of string attached with ‘!’ is true.
Read more examples of Linux “cat command” at 13 Cat Command Examples in
Linux
17. Command: cp
The “copy” stands for (Copy), it copies a file from one location to another
location.
Note: cp is one of the most commonly used command in shell scripting and it
can be used with wildcard characters (Describe in the above block), for
customised and desired file copying.
18. Command: mv
The “mv” command moves a file from one location to another location.
root@tecmint:~# pwd
/home/user/Desktop
Note: This command won’t be much frequently used in scripting but it is an
absolute life saver for newbie who gets lost in terminal in their early
connection with nux. (Linux is most commonly referred as nux or nix).
20. Command: cd
Finally, the frequently used “cd” command stands for (change directory), it
change the working directory to execute, copy, move write, read, etc. from
terminal itself.
root@tecmint:~# cd /home/user/Desktop
server@localhost:~$ pwd
/home/user/Desktop