Linux Terminal Files-related Commands

The following are Linux terminal files-related commands:

  1. file
  2. touch
  3. cat
  4. head
  5. tail
  6. tac
  7. more
  8. rm
  9. rm -i
  10. rm - rf
  11. cp
  12. cp -i
  13. cp -r
  14. mv
  15. mv -i

1. file

This command shows the file type (what is the extension and which type of file is this?).

Example

ih@linux:~$ file /home/ih/prg/ok.c
ok.c: ASCII C program text

ih@linux~# file /dev/sda
/dev/sda: block special

2. touch

This command is used to create an empty file.

Example

ih@linux:~$ touch ok1.txt
ih@linux:~$ touch ok2.txt
ih@linux:~$ ls -l
-rw-r--r-- 1 ih ih 31 Mar 15 12:52 ok1.txt
-rw-r--r-- 1 ih ih 31 Mar 15 12:53 ok2.txt

3. cat

This command is used to display the file contents.

Example

ih@linux:~$ cat /home/ih/prg/ok.c
--- file contents will display here---

This command is used to display the first 10 lines of the file.

Example

ih@linux:~$ head /home/ih/prg/ok.c
--- first 10 lines will display here---

5. tail

This command is used to display last 10 lines of the file.

Example

ih@linux:~$ tail /home/ih/prg/ok.c
--- last 10 lines will display here---

6. tac

This command is used to display file's contents in reverse order.

Example

ih@linux:~$ cat /home/ih/prg/ok.c
--line 1--
--line 2--
--line 3--
--line 4--

ih@linux:~$ tac /home/ih/prg/ok.c
--line 4--
--line 3--
--line 2--
--line 1--

7. more

This command is used to display those file's conents which are more than one screen. Press space bar to display next screen & press "q" to quit the file.

Example

ih@linux:~$ more /home/ih/prg/ok.c
--line 1--
--line 2--
--line 3--
--line 4--
.
.
.
"press space bar to display next screen".

8. rm

This command is used to remove file(s).

Example

ih@linux:~$ rm /home/ih/ok.c

9. rm -i

To prevent accidental removal, this command asks before removal file.

Example

ih@linux:~$ rm -i /home/ih/ok.c
rm: remove regular file `ok.c'? yes

10. rm -rf

Here "r" stands for recursive, and "f" stands for force. This command is used to remove everything from the given directory. However rm does not delete the directory’s all file(s)/ directory(s). Use rm –rf to remove everything.

Example

ih@linux:~$ rm /home/ih
rm: cannot remove `ih': Is a directory

ih@linux:~$ rm -rf /home/ih
ih@linux:~$ ls
ls: cannot access ih: No such file or directory

11. cp

This command is used to copy one file.

Example

ih@linux:~$ cp /home/ih/ok.c  okTemp.c
ih@linux:~$ ls
ok.c  okTemp.c

12. cp -i

This command is used to prevent overwriting of existing file.

Example

ih@linux:~$ cp /home/ih/ok.c  ok.c
cp: overwrite file ‘ok.c’: n

13. cp -r

This command is used to copy all files & subdirectories of the directory.

Example

ih@linux:~$ cp –r /home/ih  /home/backup
all files and subdirectories of directory 
"/home/ih" will be copied into "/home/backup"

14. mv

This command is used to move or rename a file.

Example

ih@linux:~$ ls
ok.c  okTemp.c

ih@linux:~$ mv  /home/ih/ok.c  xyz.c

ih@linux:~$ ls
okTemp.c  xyz.c

15. mv-i

This command is used to prevent overwriting of existing file while moving or renaming.

Example

ih@linux:~$ ls
ok.c  okTemp.c

ih@linux:~$ mv  /home/ih/ok.c  okTemp.c
mv: overwrite ` okTemp.c'? n

ih@linux:~$ ls
ok.c  okTemp.c

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.