Acknowledgment to tutorialspoint.
https://www.tutorialspoint.com/unix/index.htm
You can use the cat command to see the content of a file and display the line numbers by using the -b option along with the cat command as follows
cat -b filenameYou can use the wc command to get a count of the total number of lines, words, and characters contained in a file.
wc filenameTo make a copy of a file use the cp command.
cp source_file destination_fileTo go in your last directory
cd -To list the files in a directory
ls dirnameAn important Unix concept is the environment, which is defined by environment variables. Some are set by the system, others by you, yet others by the shell, or any program that loads another program.
A variable is a character string to which we assign a value. The value assigned could be a number, text, filename, device, or any other type of data. For example, first we set a variable TEST and then we access its value using the echo command
TEST="Unix Programming" echo $TESTIt produces the following result.
Unix ProgrammingIf we don't use the $ sign, it returns
TESTReally clear a terminal instead of simply shifting previous output upwards when you run "clear" command.
tput resetYou can connect two commands together so that the output from one program becomes the input of the next program. Two or more commands connected in this way form a pipe. To make a pipe, put a vertical bar (|) on the command line between two commands. When a program takes its input from another program, it performs some operation on that input, and writes the result to the standard output. It is referred to as a filter.
The name "grep“ means "globally search for a regular expression and print all lines containing it”. For example,
ls -l | grep "lib"There are various options which you can use along with the grep command
ls -l | grep -v "lib" # Prints all lines that do not match pattern. ls -l | grep -c "lib" # Prints only the count of matching lines. ls -l | grep -i "lib" # case insensitive searchView the history of a command
history|grep "main.py" # view all commands containing main.pyWrite the output of a command to a txt file
command >>logs.txt 2>&1 # errors and warnings includedDisk usage of all users
sudo du -shc /home/*Disk usage by subfolder
du directory-to-analyze/* -shFind the process on a specific port
sudo lsof -t -i:9001
转载于:https://www.cnblogs.com/cxxszz/p/8573773.html
相关资源:Advanced Linux Programming(中文版)