File Operation Commands in Linux (original) (raw)

Last Updated : 7 Jan, 2026

File Operation Commands in Linux are used to manage files within the filesystem, including creating, viewing, copying, moving, and deleting files. These commands help users efficiently organize and control file data through the terminal.

List of File Operation Commands

file

Below is a list of file operation commands that help in understanding how files are managed and manipulated in Linux.

1. basename

The basename command extracts the file name from a full file path. It removes directory information and displays only the file name.

**Example:

basename /home/user/file.txt

**Output:

basename

2. cat

The cat command displays the contents of a file on the terminal. It can also be used to concatenate multiple files.

**Example:

cat file.txt

**Output:

cat

3. cksum

The cksum command generates a checksum and file size. It helps verify file integrity during transfers.

**Example:

cksum file.txt

**Output:

cksum

4. cmp

The cmp command compares two files byte by byte. It reports the first difference between files.

**Example:

cmp file1.txt file2.txt

cmp

5. compress

The compress command reduces file size using compression. It creates files with a .Z extension.

**Example:

compress example.txt

**Output:

129

6. cp

The cp command copies files or directories from one location to another. It is commonly used for backups.

**Example:

cp file1.txt file2.txt

**Output:

cp

7. cpio

The cpio command creates and extracts archive files. It is often used with pipes for backups.

**Example:

ls | cpio -o > backup.cpio

**Output:

image

8. csplit

The csplit command splits a file into multiple smaller files. It works based on patterns or line numbers.

**Example:

csplit file.txt /pattern/

**Output:

9. cut

The cut command extracts specific columns or fields from a file. It is mainly used with delimited text files.

**Example:

cut -d: " " -f 2,3 sample.txt

**Output:

file

10. diff

The diff command compares files line by line. It shows the differences between two files.

**Example:

diff a.txt b.txt

**Output:

comparing file line by line in linux

11. diff3

The diff3 command compares three files simultaneously. It is mainly used for resolving merge conflicts.

Example:

diff3 a.txt b.txt c.txt

**Output:

12. echo

The echo command prints text or variables to the terminal. It is widely used in shell scripts.

**Example:

echo "Hello Linux"

**Output:

echo

13. expand

The expand command converts tabs into spaces. It improves text formatting.

**Example:

expand file.txt

**Output:

14. file

The file command identifies the type of a file. It does not rely on file extensions.

**Example:

file script.sh

**Output:

15. fold

The fold command wraps long lines to a specified width. It improves text display.

**Example:

fold -w60 GFG.txt

**Output:

fold -w[n] GfG.txt

16. head

The head command displays the first lines of a file. By default, it shows the first 10 lines.

**Example:

head sample.txt

**Output:

file

17. less

The less command displays file content page by page. It allows forward and backward navigation.

**Example:

less file.txt

**Output:

less

less-o

18. join

The join command merges two files using a common field. Files must be sorted before joining.

**Example:

join file1.txt file2.txt

**Output:

file

19. ln

The ln command creates links between files. It supports both hard and symbolic links.

**Example:

ln -s file.txt link.txt

**Output:

ln

20. locate

The locate command searches files using a database. It provides faster results than find.

**Example:

locate file.txt

**Output:

locate

21. look

The look command displays lines starting with a given string. It works on sorted files.

**Example:

look "#include" Assignment.c

**Output:

22. more

The more command displays text one screen at a time. It is a basic file viewer.

**Example:

more sample.txt

**Output:

file

23. mv

The mv command moves or renames files and directories. It performs both actions using the same command.

**Example:

mv old.txt new.txt

**Output:

mv

24. od

The od command displays file content in octal or other formats. It is useful for inspecting binary files.

**Example:

od file.txt

**Output:

od

25. paste

The paste command merges files line by line horizontally. It combines corresponding lines.

**Example:

paste a.txt b.txt

**Output:

The readlink command displays the target of a symbolic link. It resolves symlink paths.

**Example:

readlink link.txt

**Output:

readlink

27. rename

The rename command renames files using patterns. It is useful for bulk renaming.

**Example:

rename 's//.log/' *.txt

**Output:

file

28. rev

The rev command reverses characters in each line. It is a text manipulation utility.

**Example:

rev file.txt

**Output:

rev

29. rm

The rm command deletes files permanently. Deleted files cannot be recovered easily.

**Example:

rm file.txt

**Output:

image

30. shred

The shred command overwrites files multiple times. It prevents data recovery.

**Example:

shred demo.txt

**Output:

file

31. sort

The sort command sorts lines in a file. It supports alphabetical and numeric sorting.

**Example:

sort file.txt

**Output:

sort

32. split

The split command divides large files into smaller ones. It is size or line based.

**Example:

split demo.txt part_

**Output:

image

33. tac

The tac command displays file content in reverse order. It prints lines from bottom to top.

**Example:

tac tacxample.txt

**Output:

Basic tac command Example

34. tail

The tail command shows the last lines of a file. It is widely used for log monitoring.

**Example:

tail file.txt

**Output:

tail command in Linux

35. tar

The tar command creates and extracts archive files. It is commonly used for backups.

**Example:

tar -cvf archivedemo.tar demo.txt folder1/

**Output:

tar

36. tee

The tee command writes output to both file and terminal. It is commonly used with pipes.

**Example:

echo "Hello World" | tee demo.txt

**Output:

file

37. touch

The touch command creates empty files or updates timestamps. It is the fastest way to create a file.

**Example:

touch test.txt

**Output:

touch

38. unexpand

The unexpand command converts spaces into tabs. It is the reverse of expand.

**Example:

unexpand file.txt

**Output:

file

39. uniq

The uniq command removes duplicate lines from a file. It works best on sorted files.

**Example:

uniq file.txt

**Output:

filefile

40. wc

The wc command counts lines, words, and characters. It is useful for text analysis.

Example: wc file.txt

**Output:

wc