Linux Command Line(II): Intermediate

时间:2023-03-09 01:51:45
Linux Command Line(II): Intermediate

Prerequisite: Linux Command Line(I): Beginner

================================

File I/O

$ cat > a.txt  #create a file 'a.txt' and appends things into it

Type random stuff...

# press Ctrl+d to exit editting

$ cat a.txt

Type random stuff...

$ cat > a.txt  #'single >' for overwriting the entire document 

Overwritting in process...

#Ctrl+d

$ cat a.txt

Overwritting in process...

$ cat >> a.txt  #'double >>' for  appending to the EOF

appending in process...

#Ctrl+d

$ cat a.txt

Overwritting in process...

appending in process...

==================

Concatenating 2 txt files

cat a.txt b.txt > out.txt  #transfer the content of these 2 .txt and to a new .txt

cat a.txt b.txt > b.txt    #error! using 'cat <' input and output cannot be same

cat a.txt >> b.txt    #okay: content of a.txt appends to b.txt

==================

 Mkdir

Greedy method: >2 directories at a time

mkdir -p notebook/new

mkdir -p /notebook/new  #error!

mkdir -p friends/{John, Tom, Amy}  #with space, only 1 directory created

mkdir -p friends/{John,Tom,Amy}  #3 directories created

rm -r friends   #remove non-empty directories & itself

===================

cd

cd ..  # go up one directory

====================

output script into txt 

script out.txt

# type some commands

exit

====================

remove all files within a directory without removing the folder

rm Documents/*  #suppose we are at /root

===================