Linux commands - File system

All Linux files are organised into directories. These directories are organised into a tree-like structure called the filesystem.

The ls command list out all the files or directories available in a directory.

ls

ls -l

ls -w

command example for ls

The command cd is used to switch between directories. Without any directory name specified, it switch to the current user HOME directory.

cd

The command mkdir is to create a new directory.

mkdir name_of_directory

The command rm deletes a given name of file. The command rmdir deletes a directory. 

rm name_of_file

rmdir name_of_directory

The command mv moves a file OR directory to another directory location. It is also used to rename a file, when mv is used within the same directory.

mv

The command cat displays content of a text file.

cat

The command cp makes a copy of existing file ot current directory or to another directory.

cp

The command pr convert text files for printing where it can add headers and page width.

pr

The command pwd display the current directory of the user

pwd

The command find search a given directory for files.

find

Find a given file name in current directory

find . -name "storage"

Find a given file name in directory /home

find /home -name "storage"

Find a given directory name in directory /home. Where type d=directory, and f=ordinary file

find /home -type d -name "storage"

Find a ordinary file permission 777 in current directory

find . -type f -perm 0777 -print

Find a ordinary file WITHOUT permission 777 in current directory

find . -type f ! -perm 0777 -print

The command diff compare 2 files line by line and list their differences. The symbols a=add, c=changed, d=deleted indicate changes from first file to right side file.

diff

$ diff apple.txt orange.txt

2c2

< apple

---

> Orange

The command mount attaches file systems to a mount point. Wuth the option -a, it will load mount points as mentioned in /etc/fstab

mount

mount -t ext4 /dev/sdb1 /mnt/media

The command grep search for file contents given a string and directory

grep

grep "Fruits" *

The command head retrieve the top part of a file. It defaults to the first 10 lines.

head

The command tail retrieve the bottom part of a file. It defaults to the last 10 lines.

tail

No comments:

Blog Archive