Linux commands List for Linux Programming – Part 3


1. Objective

This Linux Commands tutorial covers Linux commands list for beginners. It will help you in learning 10 most commonly used Linux commands with syntax to start Linux programming. You will also get few Linux commands with examples here. It will cover commands like pwd, cd, ls, mkdir, rmdir, echo, cat, zcat, cp and mv.

So here you go!!!

linux commands list

2. Linux Commands List

2.1. pwd

a. Usage:

pwd

This command is used to print working directory

b. Usage:

d= `pwd`

This command is used to save current working directory.

c.Usage:

cd $d

This command is used to go back to the saved directory.

2.2. cd

a. Usage:

$ cd /<some path>

This command changes directory to the specified path.

b. Usage:

$ cd

This command will take you to home if path is not mentioned.

c. Usage:

$ cd /

This command is used to go to root directory.

d. Usage:

$ cd ..

This command will move one back towards root directory.

e. Usage:

$ cd –

This command is used to move to the previous directory.

2.3. ls

a. Usage:

$ ls

This command lists all the files and directories in the current working directory.

b. Usage:

$ ls <file or directory name>

This command will list the contents present in the specified file or directory.

c. Usage:

$ ls –l

This command displays file in columns with more details like owner of file, File size, date etc.

d. Usage:

$ ls –hl

This command lists the file in human readable long form(change bytes into kilobytes,gigabytes etc).

e. Usage:

$ ls –hlt

This command lists the file in human readable form sorted by time to last modified.

f. Usage:

$ ls –al

This command lists all files in the directory including dot files.

g. Usage:

$ ls *.txt<may be other extension>

This command lists all the files in the directory which have .txt extension.

2.4. mkdir

a. Usage:

$ mkdir <directory name>

This command makes new directory/folder with mentioned name.

b. Usage:

$ mkdir -p a/b/c

This command creates nested directories a>b>c.

2.5. rmdir

a. Usage:

$ rmdir <empty directory name>

This command removes the directory which is empty.

b. Usage:

$ rm -r <non empty directory>

This command removes non empty directory.

2.6. echo

a. Usage:

$ echo <String>

This command prints the string passed to echo as an arguments.

b. Usage:

$ echo

This command leaves blank line if you leave arguments.

c. Usage:

$ echo "hello world"

This command prints the given string with spaces.

d. Usage:

$ echo -e "\thello\nworld"

This command interprets special characters.

e. Usage:

$ echo -n <String>

This command suppresses the next line to the given string.

f. Usage:

$ echo $name

This command prints the value containing in name with expanded variable.

2.7. cat

a. Usage:

$ cat file1.txt

This command displays the contents of file1.

b. Usage:

$ cat file1.txt file2.txt

This command displays contents of both the files in different lines.

c. Usage:

$ cat -n file1.txt

This command prints file content with line number.

d. Usage:

$ cat flle1.txt>>file2.txt

This command appends the content of file2 after file1 content.

e. Usage:

$ cat file1.txt file2.txt>>file3.txt

This command appends the content of file1 after the content of file3 and then appends file2 content.

f. Usage:

$ cat file1.txt | wc –l

This command counts the number of lines in the file1.txt.

g. Usage:

$ cat file1.txt | wc –c

This command counts the character in file1 including space.

2.8. zcat

a. Usage:

$ zcat file1.txt.gz

This command display the content of zip file.

2.9. cp

a. Usage:

$ cp file1 file2

This command copies the content of file1 into file 2(overide).

b. Usage:

 $ cp -R dir1 dir2 

This command recursively copies the dir1 into dir2.

2.10. mv

a. Usage:

 $ mv file1 file2 

This command renames the file1 by the file2 name.

b. Usage:

 $ mv file1 dir1/dir2/file2 

This command will move the file1 to dir1/dir2/ and renames file1 by file2.

c. Usage:

 $ mv file1 dir1/dir2/ 

This command will only move the file1 in dir1/dir2.

d. Usage:

$ mv a a.1
$ mv b a
$ mv a.1 b 

This command will swipe the name of two files.

e. Usage:

$ mv file1.txt file1.html 

shortcut $ mv file1.{txt,html}

This command changes the extension of file1 from .txt to .html.

f. Usage:

 mv -n file1 dir1/ 

If in dir1 the same file1 exists, so it will be overwritten by the file1 which we are moving.

Learn more commands in Linux Commands – Part 4.

Source:

http://linuxcommand.org/

Leave a comment

Your email address will not be published. Required fields are marked *