Updated March 18, 2023
Introduction to Commands in Linux
Commands in Linux are generally referred to as inbuilt Programs, whenever you run a particular command, it will execute a particular program and perform its operation. These commands are in a Linux terminal. A Linux terminal is something that provides a command-line interface that will allow the user to execute the commands.
Top 13 Linux Commands
The Top Commands are given below:
1. pwd
Displays the full path-name of the current working directory.
Example:
$pwd
/usr/pethu
2. cd
To change the directory. If the directory is specified, the directory becomes the new working directory. Otherwise, it will take the user back to the user’s HOME directory.
Example:
$cd ppk
$pwd
/usr/pethu/ppk
$cd..
$pwd
/usr
$cd
$pwd
/usr/pethu
3. mkdir
To create a new directory.
Syntax:
mkdir dirname
Example:
$mkdir imp
4. ls
Displays the files and subdirectories in the current directory.
Example:
$ls
Kirshna
Ppk
Syed
5. File Permissions Commands
Given below are some of the File Permissions:
chmod:
This command can be named to put three authorization for all the three categories of file users. The individual who owns the file has access to and uses the files. The chmod command uses an expression as its argument that joins, the operation, permission types, and the category, by effectively using effective abbreviations.
The below table shows the abbreviations that utilize the three factors of these expressions:
Category | Operation | Attribute |
u – user | + assign permission | r – read permission |
g – group | – remove permission | w – write permission |
o – other | = assign absolute permission | x – execute permission |
a – all |
Example:
- chmod u+x ppk: The command assign (+) executable (x) permission for the user (u), other permissions remaining unchanged.
- chmod ugo+x ppk: The string ugo combines all the three categories user, group and others.
- chmod u+x ppk Syed Krishna: chmod also accepts more than one filename in the command line.
6. Octal Notation
Some of the Octal Notation explained below:
Example:
chmod 666 ppk:
- The 6 indicates to read and write permissions (4+2).
- The 4 indicates read permission.
- The 2 indicates write permission.
- The 1 indicates executable permission.
7. File Copy Commands
Some of the Commands explained below:
- cp: The cp (copy) command copies a file or a group of files
Syntax:
cp [options] <source path | source file> <target path | target filename>
Example:
$cp ppk ppk1
If the destination file doesn’t exist. It will first be created before copying takes place. If not, it will simply be overwritten.
$cp ppk progs/ppk1
The file ppk is copied to the directory progs with the name ppk1.
Example:
$cp ppk01 ppk02 ppk03 progs
All files after copying will retain their original names. It is not possible to specify target filenames for each file, and copying takes place only if the progs directory exists. Remember that if these files are already resident in progs, then they will simply be overwritten.
Options in cp Commands:
- -i –> Option
$ cp -i ppk ppk1
cp: overwrite ppk1? y
If the target file already exists then this option will ask the confirmation to overwrite it. If your choice is ‘y’ then it will overwrite the contents. If your choice is ‘n’ then it will not overwrite the contents.
- -r –> Recursive Option
$ cp -r progs new progs
It is now possible to copy an entire directory structure using the -r (recursive option). This will copy files and sub-directories in progs to new progs.
8. Deleting Commands
Given below are some of the Deleting Commands:
- rm: This command is used to delete the files
Syntax:
rm [options] [filename(s)]
Example:
$rm ppk ppk1
It will delete the files ppk and ppk1
Example:
$rm *
It will remove all the files in the current directory
Options in Delete Commands
-i: $ rm -I ppk ppk1
ppk:?y
Ppk1:?n
If you press a y after this message, then the file will be deleted.
-r : $rm -r pethu
It will delete the pethu directory and its subdirectories.
9. Renaming File Commands
Some of the Renaming File Commands are given below:
- mv: This command is used to rename the files
Syntax:
+mv [filename(s)]
Example:
$mv ppk ppk2
Rename the file ppk ppk2.
$mv ppk pkk1 progs
Move the files ppk ppk1 to the progs directory.
$mv progs progs1
It will rename directory progs to progs1
10. Calendar Commands
Given below are some of the Calendar Commands:
- cal: This command is used to print the calendar.
Syntax:
cal [month][year]
Example:
$cat
If no argument is specified then it will print the previous month, current month & the next month.
$ cat Jan
It will print the current years January month calendar.
$cat Jan 1996
It will print the 1996th year’s January month calendar.
$cat 1996
It will print the one-year calendar for the year 1996.
11. Displaying the System Date Command
- date: It is used to print and set the date.
Syntax:
date [MMddhhmm[yy]][+format]
- MM: Month number.
- dd: Day number in the month.
- hh: Hour number (24 – hour system).
- mm: Minute number.
- yy: Last 2 digits of the year number(optional).
Example:
$date
Prints the current date and time.
12. Login Details Commands
Given below are some of the Login Details Commands:
- who: Linux maintains an account of all the current users of the system. It is a good idea to know the people working on the various terminals so that you send them messages directly. A list of them is displayed by the who command, which, by default, produces a three -columnar.
Syntax:
who [optional][filename]
Example:
$who
root
syed
pethu
$who am I
pethu
13. Comparing Two Files Commands in Linux
Some of the commands are given below:
- cmp: It compares two files and if they are different, display the byte and line number of the differences.
Syntax:
cmp [<option(s)>] <filename1> <filename2>
Example:
$cmp ppk ppk1
ppk ppk1 differ: char 9, line 1
Conclusion
Linux is an operating system with interface provider, but unlike other operating systems it has various advantages that make Linux a top priority it is an open-source operating system free of cost, secure compared to other OS, easily customized to our preferences and It is stable compared to windows especially when we are using large bits of data and even in the deployment process, the environments are mostly Linux hence various applications that are deployed in cloud uses Linux environment.
Recommended Articles
This is a guide to Top Commands in Linux. Here we discuss the introduction and top 13 linux commands for better understanding. You can also go through our other suggested articles to learn more –