Skip to main content

File Management Commands in Linux

Once you have a little bit of idea about the terminal, Linux command structure, path and directory hierarchy system, you should know about handling files in Linux.

As a Linux user, you have to deal with all kinds of files and all kinds of file operations.

You should know how to display the contents of files, create new files, change their properties. You should also know how to look for files and edit them.

In this section of Linux Handbook, you'll learn about various Linux commands that you can use for file managements.

I have categorized the commands into sections so that it is easier for you to follow.

Basic file commands

Form listing files to copying them, these commands will help you.

Command Description Example
ls List files in a directory ls command examples
cp Copy files and directories cp command examples
mv Move (rename) files and directories mv command examples
ln Create links to files and directories ln command examples

Directory operation commands

These commands will handle creating, moving around and removing directories.

Command Description Example
cd Navigate between directories cd command
mkdir Create new directories mkdir command
rmdir Delete the empty directories rmdir command

File viewing commands

View the contents of a file in Linux terminal with these commands:

Command Description Example
cat Join several input files by sequentially or display contents cat command
head Print a specified number of lines from the beginning of the file head command
tail Outputs the last parts of a single file or multiple files tail command
less Viewing text files less command
more Opens a text file in page views more command

File editing commands

Edit files in the terminal with these editors:

Command Description Example
Vim Popular command line text editor Vim commands
Emacs Popular Text Editor Emacs commands

File properties commands

Learn about the timestamps, size, number of lines and many more such attributes of files with these commands:

Command Description Example
wc Count the number of lines, words and characters of text file wc command
chgrp Changing the group of a file or directory chgrp command
touch Changing file timestamps/creating new empty file touch command
chmod Changing the mode of access chmod command
du Checking the size of directory du command
file Determine actual type of file and related information file command
stat Get file attribute information stat command
chown Change user and group ownership of a file/directory chown command
chattr Make a file 'undeletable' even by root chattr command

File searching commands

These commands will let you search for files on your system.

Command Description Example
which Locates an executable file in your shell’s search path which command
locate Preform a super quick search for files locate command
xargs Build and execute commands from standard input xargs command
find Searching for files and directories find command

File manipulation commands

Manipulate the output of text files with these commands

Command Description Example
grep Find patterns in files grep command
cut Removing “columns” or data on each line of a text file cut command
paste Merges several input files to produce a new delimited text file paste command
tee Reads from standard input and writes to both standard output and files tee command
expand Convert the tabs into spaces expand command
tr Translating one type of characters into another tr command
sort Sorting the contents of the text files sort command
uniq Filtering duplicate text from a file uniq command