w3resource logo
gallery w3resource

Linux commands for newbies

 

In this slide presentation you will learn several Linux commands which will be useful for somebody who is just starting with Linux.

Transcript

Linux commands for newbies

In the following slides you will learn several Linux commands which will be useful for somebody who is just starting with Linux.

Command: ls

ls, stands for List Directory Content is a command to return a list of the files and directories residing within a directory. Default directory which it considers is the current directory.

datasoft @ datasoft-linux ~$ ls
abc1pqr.txt
abc1.txtpsr1.sh
ABC.pngpsr1.sh~
abc.txtpsr2.sh
ajax-php-mysql-user-interface.htmlpsr2.sh~
…………
………...

Command: ls -l

Adding a l option returns long listing. i.e. you can see permissions, user, group, date/time of creation of the file.

datasoft @ datasoft-linux ~$ ls -l
total 2324
-rw-rw-r-- 1 datasoft datasoft19 Aug 7 17:02 abc1
-rw-rw-r-- 1 datasoft datasoft19 Aug 7 17:02 abc1.txt
-rw-rw-r-- 1 datasoft datasoft0 Jul 29 13:39 ABC.png
-rw------- 1 datasoft datasoft107 Aug 2 16:07 abc.txt
-rw------- 1 datasoft datasoft1790 Sep 14 2013 ajax-php-mysql-user-interface.
html
……………
……………...

Command: lsblk

lsblk stands for List Block Devices. It prints block devices (excluding RAM) by their assigned name on the standard output in a tree-like fashion.

datasoft @ datasoft-linux ~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 465.8G 0 disk
├─sda1 8:1 0 73.2G 0 part
├─sda2 8:2 0 1K 0 part
├─sda5 8:5 0 97.7G 0 part
├─sda6 8:6 0 97.7G 0 part
├─sda7 8:7 0 97.7G 0 part
├─sda8 8:8 0 52.2G 0 part
├─sda9 8:9 0 45.5G 0 part /
└─sda10 8:10 0 1.9G 0 part [SWAP]

Command: lsblk - l

Unlike lsblk, lsblk -l returns a list block devices in list structure instead of tree like structure.

datasoft @ datasoft-linux ~$ lsblk -l
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 465.8G 0 disk
sda1 8:1 0 73.2G 0 part
sda2 8:2 0 1K 0 part
sda5 8:5 0 97.7G 0 part
sda6 8:6 0 97.7G 0 part
sda7 8:7 0 97.7G 0 part
sda8 8:8 0 52.2G 0 part
sda9 8:9 0 45.5G 0 part /
sda10 8:10 0 1.9G 0 part [SWAP]
datasoft @ datasoft-linux ~$

Command: md5sum

The “md5sum” stands for Compute and Check MD5 Message Digest. md5sum is a computer program that calculates and verifies 128-bit MD5 hashes. It is widely used to check whether file transferring (e.g. downloading) a file has been changed or not because of faulty file transfer, a disk error or non-malicious meddling

datasoft @ datasoft-linux ~$ md5sum VNC-5.2.0-Windows.exe
0eb0d0394663bbd940a2878c3468f599 VNC-5.2.0-Windows.exe

Command: uname

The “uname” command stands for Unix Name. It prints information about
the machine name, Operating System and Kernel.

datasoft @ datasoft-linux ~$ uname
Linux

Command: history

The “history” command prints the history of long list of executed commands in terminal.

datasoft @ datasoft-linux ~$ history | more
1024 cd datasoft
1025 ls
1026 sort -k1 abc.txt
1027 sort -k2 abc.txt
1028 cat xyz.txt
1029 sort xyz.txt
1030 sort -k3 abc.txt
1031 sort -n -k3 abc.txt
1032 cat abc.txt
1033 sort abc.txt

Command: sudo

sudo refers to the file /etc/sudoers to determine who is an authorized user while executing a command which requires a little more privilege than the current user has.

datasoft @ datasoft-linux ~$ sudo
usage: sudo -h | -K | -k | -V
usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]
[command]
usage: sudo [-AbEHknPS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p
prompt] [-u user] [VAR=value] [-i|-s] [<command>]
…………………….
……………………..

Command: mkdir

The mkdir (Make directory) command creates a new directory with name supplied after the command mkdir. It returns “cannot create folder, folder already exists” error if the the directory mentioned already exists.

datasoft @ datasoft-linux ~$ mkdir mydir.

Command: touch

The “touch” command stands for Update the access and modification times of each FILE to the current time. the command creates the file if does not exist, else it modifies the timestamp keep the contents of the file unaltered.

datasoft @ datasoft-linux ~$
touch myfile

Command: chmod

The Linux “chmod” command stands for change file mode bits. It is used to change the permission(s) of the file associated.

datasoft @ datasoft-linux
~$ chmod 755 myfile

Command: chown

The Linux “chown” command stands for change file owner and group.

datasoft @ datasoft-linux
~$ chown myfile user10
chown: invalid user: ‘myfile’
datasoft @ datasoft-linux
~$ chown user10 myfile
chown: changing ownership
of ‘myfile’: Operation not
permitted

Command: apt

apt command stands for (Advanced Package Tool. Apt is an advanced package manager for Debian based system (Ubuntu, Kubuntu, etc.). It is used to search, install, update and resolves dependency of packages on Gnu/Linux System from command line.

datasoft @ datasoft-linux ~$ sudo apt-get update
Ign http://security.ubuntu.com trusty-security InRelease
Ign http://extras.ubuntu.com trusty InRelease
Ign http://in.archive.ubuntu.com trusty InRelease
Get:1 http://security.ubuntu.com trusty-security Release.gpg [933 B]
Hit http://extras.ubuntu.com trusty Release.gpg
Get:2 http://security.ubuntu.com trusty-security Release [59.7 kB
…………………………..
…………………………...

Command: tar

The tar program is used to create, modify, and access files archived in the tar format. "tar" stands for tape archive. It is an archiving file format.

datasoft @ datasoft-linux
~/dir2$ tar -cvf files.tar
myfile myfile2
myfile
myfile2
datasoft @ datasoft-linux
~/dir2$ ls
files.tar myfile myfile2
datasoft @ datasoft-linux
~/dir2$

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.

datasoft @ datasoft-linux
~/dir2$ cal

August 2014
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

Command: date

The “date” (Date) command print the current date and time on the standard output, and can further be set.

datasoft @ datasoft-linux
~/dir2$ date
Wed Aug 20 12:52:54 IST
2014

Command: cat

The “cat” stands for Concatenation. Though it is generally used to display contents of files from command line, it can also be used to copy text files, combine text files and create new text files.

datasoft @ datasoft-linux
~$ cat myfile
this is file for demo

Command: cp

cp stands for Copy. It copies a file from one location to another location.

datasoft @ datasoft-linux
~$ cp myfile dir2/

Command: mv

mv command moves a file from one location to another location.

datasoft @ datasoft-linux ~$
mv myfile dir2/

Command: pwd

pwd command is used to display the name of the current / present working directory.

datasoft @ datasoft-linux ~$
pwd
/home/datasoft

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.

datasoft @ datasoft-linux
~$ cd dir2