Common operating commands for Linux files

1. Daily operation commands

**View the current working directory

pwd

**View current system time

date

**See who's online (who's logged into the server)

who View current online

last View recent login history

2. File system operations

**

ls / View information on child nodes (folders and files) under the root directory

ls -al -a is for hidden files -l is for a more detailed list

**Switch directory

cd / home

**Create folder

mkdir aaa This is the way to write a relative path

mkdir -p aaa/bbb/ccc     

mkdir /data This is the way to write the absolute path

**Delete folder

rmdir can delete empty directories (not much used)

rm -r aaa can delete the entire folder aaa and all its subnodes

rm -rf aaa Force delete aaa

**Modify the folder name

mv aaa angelababy

**Create a file

touch somefile.1 creates an empty file

echo "i miss you, baby" > somefile.2 Using the redirection ">" function, the output of a command is written to a file, which will overwrite the content of the original file

echo "i miss you too" >> somefile.2 appends the output of a command to a file without overwriting the content of the original file

Edit the generated file with the vi file editor

vi somefile.4

1. First enter the "general mode", this mode only accepts various shortcut keys and cannot edit the file content

2. Press the i key to switch from the normal mode to the editing mode. In this mode, the contents of the file are all typed in.

2. After editing, press ESC to exit the editing mode and return to the normal mode

4. Press ":" again to enter the "bottom line command mode", enter the wq command, and press Enter.

Some useful shortcut keys (used in normal mode)

a start inserting one position after the cursor

A is inserted at the end of the row

I insert at the beginning of the line

gg jumps directly to the first line of the file

G jumps directly to the end of the file

dd delete line, if 5dd, delete 5 lines after the cursor at one time

yy Copy the current line, copy multiple lines, then 3yy, copy the three lines near the current

p paste

v Enter character selection mode, after the selection is complete, press y to copy, press p to paste

ctrl+v to enter block selection mode, after the selection is complete, press y to copy, press p to paste

shift+v to enter the row selection mode, after the selection is complete, press y to copy, press p to paste

find and replace (entered in low level command line mode)

%s /sad/88888 Effect: Find all sad in the file and replace with 88888

/you effect: find the you appearing in the file, and locate the first found place, press n to locate the next matching location (press N to locate the previous one)

******Copy file

cp  somefile  /home/hadoop/

******View file content

cat somefile will output all the contents of the file at one time (console)

more somefile can be paged to view, page down (space), page up (b) exit (q)

less somefile can be paged to view, one page down (space), one page up (b), exit (q), one line up (↑), one line down (↓), search keyword (/keyword)

tail -10 install.log View the last 10 lines of the file

tail -f install.log Small f tracks the unique inode number of the file, even if the file is renamed, it still tracks the file represented by the original inode

tail -F install.log Big F to track by file name

head -10 install.log View the 10 lines at the head of the file





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324602469&siteId=291194637