File Manipuation
# create file
touch test.txt
# copy file
cp /path/to/original /path/to/copy
# copy folder recursively
cp -r /path/to/original /path/to/copy
# move file or folder
mv /path/to/source /path/to/target
Look Through Dir
# list files, one file per line
ls -1
# list files with more info
ls -l
# list all files including hidden
ls -a
# with human readable file size
ls -lh
# sort based on size
ls -lhS
# sort based on update time
ls -ltr
Look Into File
First several lines
head filename
# first n lines
head -n filename
Last several lines
tail filename
# last n lines
tail -n filename
Check all content
# can search keyword and only print those lines
cat filename | grep "some keyword"
Interactive
less [option] filename
ps -ef | less -N
Command
<space>
: next page
b
: previous page
g
: jump to the start
G
: jump to the end
q
: quit
/query_string
: forward find string
?query_string
: backward find string
n
: repeat last search
N
: repeat last search backwards
Options
-m
: percentage like more
-N
: line number
Count in file
wc -l filename
: how many lines
wc -w filename
: how many words
wc -c filename
: how many chars
Copyright claim: File and folder manipulating techniques in shell is created by melonskin on 2017/07/11. Its copyright belongs to the author. Commercial usage must be authorized by the author. The source should be included for non-commercial purposes.
Link to the article: https://amelon.org/2017/07/11/file-manipulation.html