>
Home

登龙(DLonng)

选择大于努力

Linux 系统基础 - 文件系统命令


版权声明:本文为 DLonng 原创文章,可以随意转载,但必须在明确位置注明出处!

File system command mainly included 3 points :

  1. common command.
  2. zip and tar.
  3. compare and merge.

Common Command

ls

Using ls to list file :

ls /

cd

Using cd to enter a directory :

# Enter root directory.
cd /

whereis

Using whereis file to find the location of a file :

whereis ls

pwd

Using pwd to get current directory path :

pwd

file

Using file file_name to get the type of file infomation :

file 1.txt

echo

Using echo to print some characters :

echo "Hello Linux"

mkdir

Using mkdir to create a directory :

mkdir work_space

rmdir

Using rmdir to delete a empty directory :

rmdir work_space

cat

Using cat to show a file content :

cat 1.txt

more

Using more to show a file content and flip :

# Enter: next line,Space: next page.
more 1.txt

less

Using less to show a file content and can be forward or back page :

# Enter: next line,Space: next page,f: forward,b: back
less 1.txt

cp

Using cp to copy file :

cp 1.txt 1.txt.bak

mv

Using mv to move or rename file :

# move 1.txt to ../
mv 1.txt ../

# rename 1.txt to 2.txt
mv 1.txt 2.txt

rm

Using rm to delete file or directory :

rm 1.txt 
rm work_space -rf

touch

Using touch to create a file :

touch 3.txt

chown

Using chown to change file owner :

sudo chown root 1.txt

chgrp

Using chgrp to change file group :

sudo chgrp root 1.txt

chmod

Using chmod to change file permissions :

# Hightest permissions.
sudo chmod 777 1.txt

# User add read-write-exe permissions.
sudo chmod u+rwx 1.txt

# Group delete rwx.
sudo chmod g-rwx 1.txt

# Other = permissions
sudo chmod o=rwx 1.txt

# All(User,Group,Other) = rwx = (7,7,7)
sudo chmod a=rwx 1.txt

grep

Using grep to find something in file :

grep "Hello" 1.txt

find

Using find to search something :

find 1.txt

# In current dir, find a file name with 1.* 
find . -name "1.*"

locate

Using locate to find file,first than find :

locate 1.txt

ln

Using ln to create link :

# Soft link.
ln -s 1.txt 1.txt.ln.s

# Hard link.
ln -P 1.txt 1.txt.ln.p

Note: we often create soft link.

zip and tar

gzip

Using gzip to compressed file :

# 1.txt -> 1.gz
gzip 1.txt

# 1.gz -> 1.txt
gzip -d 1.gz

tar

Using tar to pack file :

# 1.txt -> 1.tar
tar -czvf 1.tar 1.txt

# 1.tar -> 1.txt
tar -xzvf 1.tar

Compare And Merge

diff

Using diff to compare file :

# Compare 1.txt and 2.txt
diff -y 1.txt 2.txt

# Compare with patch 
diff -u 1.txt 2.txt

# Export the patch into a file.
diff -Nu 1.txt 2.txt > 12.patch

patch

Using patch to patch up :

# Automatic matching patch.
patch -p0 < 12.patch

DLonng at 06/25/17