Linux commands Syntax
$command options arguments
Let’s start with some simple commands.
1. pwd and ls command
/‘pwd’ command prints the absolute path to current working directory.
and ls command is used to list all files inside current directory.
$ cd /usr/share/
$ cd doc
The above command does the following thing:
checks the current directory.
change the directory to /user/share/
check the current directory.
change the directory to doc/
check the current directory.
2. cal command
$ cal‘cal ’ is also used to display calendar for the specified month and year. Here the month and year are arguments.and the command is :
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
$ cal 3 2021This command is used to display the calendar of 2021 march.
3. echo command
$ echo “sapkotasunil.com.np”To save something in a file you can use this command like:
$ echo “this is the content of the file” >> file.txt
4. id command
$ id uid=1000(sunil) gid=1000(sunil) groups=1000(sunil),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev)
5. date command
$ date Fri Jul 6 01:07:09 IST 2012
6. clear command
7. Listing File And Directories Command
$ ls [files-or-directories-names]List all the files and/or directories. If no argument is given, the contents of current directory will be shown.
$ ls example file1.txt file2.txt file3.txt
8. mkdir command
$ mkdir dirName
9. touch command
$ touch file1
10. copy, move and remove command
$cp source destinationCopy files and directories. If the source is a file, and the destination (file) name does not exit, then source is copied with new name i.e. with the name provided as the destination.
$ cp usrlisting listing_copy.txtTo remove files and directories
$ rm files|directoriesA directory must be removed recursively with -r option.
$ rm -r folder1you can also use “rmdir” command to remove an empty directory.
11. cat command
$ cat /etc/passwd
12. grep command
$ grep pass /etc/passwd
$ nano hello.txtHaving made all the changes to the file, press ‘ctrl+o’ to write the changes to the file and ‘ctrl+x’ to exit from the editor. There are a lot of functions available with this editor. The help menu can be accessed with ‘ctrl+g’ keystrokes.
14. Shutdown Command
$ shutdown -h now
15. Get help for any command in case your don't know how to use or forget.
i) help option
With almost every command, ‘–help’ or “-h” option shows usage summary for that command.
$ date –help
Usage: date [OPTION]… [+FORMAT] or: date [-u|–utc|–universal] [MMDDhhmm[[CC]YY][.ss]] Display the current time in the given FORMAT, or set the system date.
ii) whatis command
This command gives a one line description about the command which used as a quick reference for any command.
$ whatis date
date (1) – print or set the system date and time
$ whatis whatis
whatis (1) – display manual page descriptions
iii) Manual Pages
For more detailed information, Linux provides man pages and info pages. To see a command’s manual page, man command is used.
$ man date
The man pages are properly documented pages. They have following sections:
NAME: The name and one line description of the command.
SYNOPSIS: The command syntax.
DESCRIPTION: Detailed description about what a command does.
OPTIONS: A list and description of all of the command’s options.
EXAMPLES: Examples of command usage.
FILES: Any file associated with the command.
AUTHOR: Author of the man page
REPORTING BUGS: Link of website or mail-id where you can report any bug.
SEE ALSO: Any commands related to the command, for further reference.
iv) Info pages
Info documents are sometimes more elaborate than the man pages.These are like web pages. Internal links are present within the info pages. These links are called nodes. Info pages can be navigated from one page to another through these nodes.
$ info date