Monday, April 8, 2013

Most useful Linux basic commands for beginners

Beginners must know the following most useful commands to start working on Linux. The basic linux commands can be categorized as file and Directory manipulation commands, Managing file permissions, File system commands, Find files and search strings commands, Manage users commands. Let us start this series with most basic file and directory manipulation commands with examples.

File and Directories manipulation commands

To create a file with file name “linux.txt” , press “control+D” to save the file.
# cat > linux.txt
Tutorial on Linux command

Read the file with filename
# cat Linux.txt
Tutorial on Linux command

List the files in current directory
# ls -l
total 4
-rw-r--r-- 1 root root 26 Apr  8 22:56 Linux.txt

Create directory using "mkdir" command
# mkdir test

Find out Present working directory  using command "pwd"
# pwd

Change directory using "cd" command
# cd test
# pwd

Change directory to parent directory using “cd ..”
# cd ..
# pwd

Remove files using “rm command”
# ls -l
total 4
-rw-r--r-- 1 root root    0 Apr  8 23:03 Linux.txt
drwxr-xr-x 2 root root 4096 Apr  8 23:03 test

# rm Linux.txt
rm: remove regular empty file `Linux.txt'? y

# ls -l
total 4
drwxr-xr-x 2 root root 4096 Apr  8 23:03 test

Remove directory using “rm –r” command
# ls

# rm -r test

rm: remove directory `test'? y
# ls

Rename file or directory using "mv" command
# ls
# mv Linux.txt commands.txt

# ls

Create copy of a existing files using "cp" command

# ls

# cat commands.txt
Tutorial on Linux command

# cp commands.txt commands_2.txt

# ls
commands_2.txt  commands.txt

# cat commands_2.txt
Tutorial on Linux command

I have covered very basic versions of the file manipulation commands but each above command has several options which provide more facility with that operation. you can explore by referring the man page of each command. Man page is a help page specifies the command purpose and the options available for the command and examples.

To view man page of any command , run the  following command.

# man

The another way of getting options available for command is
# command --help                                                 
# command -?                                                     

For example
# cat --help
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s), or standard input, to standard output.

  -A, --show-all           equivalent to -vET
  -b, --number-nonblank    number nonempty output lines
  -e                       equivalent to -vE
  -E, --show-ends          display $ at end of each line
  -n, --number             number all output lines
  -s, --squeeze-blank      suppress repeated empty output lines
  -t                       equivalent to -vT
  -T, --show-tabs          display TAB characters as ^I
  -u                       (ignored)
  -v, --show-nonprinting   use ^ and M- notation, except for LFD and TAB
      --help     display this help and exit
      --version  output version information and exit

With no FILE, or when FILE is -, read standard input.

  cat f - g  Output f's contents, then standard input, then g's contents.
  cat        Copy standard input to standard output.

We will go through more command in next part.

Please leave your comments. Thanks.
Pin It
Related Posts Plugin for WordPress, Blogger...