|
Are you planning to switch from Windows to Linux, or have you just switched to Linux? Oops!!! What am I saying — whatever reason brought you into my world. From my past experience, when I first started using Linux, commands, terminals and all that really scared me. I worried about how many commands I needed to memorize to help me complete all my tasks. Undoubtedly, online documentation, books, man pages, and the community helped me a great deal, but I still firmly believe there is an article that records the secret to easily learning and understanding commands. This motivated me to master Linux and make it easy to use. This article is the stepping stone to getting there. |
Lesus
|
1. ls CommandThe ls command stands for List Directory Contents. Running it lists the contents of a folder, which could be files or folders.
The “ls -l” command lists the contents of a folder in long listing fashion.
The "ls -a" command lists all contents in a folder, including hidden files starting with ".".
Note:在LinuxIn Linux, files starting with“.”are hidden files, and every file, folder, device or command is treated as a file.ls -l Command output:
more"ls"See examples at 15 Basic ‘ls’ Command Examples in Linux |
Lesus
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Other translations (1) |
2. lsblk Command"lsblk"lists block devices. Apart fromRAM, it displays in a standard tree-likeoutputformat, neatly showing block devices.
“lsblk -l”command displays block devices in list format(rather than tree format)。
Note:lsblkis the most useful and simplest way to understand新insert的USBdevice names, especially when working with disk/block devices in the terminal. 3. md5sum Command“md5sum”calculates and verifiesMD5message digests.md5 checksum(Commonly known as hash)is used to match or verify file integrity, as files may change due to transmission errors, disk errors, or non-malicious interference.
Note: Users can compare the officially provided and md5sum generated signatures to detect if a file has changed. md5sum is not as secure as sha1sum, which we will discuss later. |
Lesus
|
4. dd Command“dd”command stands for convert and copy files. It can be used to convert and copy files, most commonly used to copyiso文件(or any other file)to ausbdevice(or any other location), so it can be used to createUSBlauncher。
Note: In the above example,usbdevice issdb1(You should uselsblkcommand to verify it, otherwise you may overwrite your disk or system), use disk names with caution. dd command during execution, depending on file size and type and usband device read/write speed, may take from a few seconds to several minutes. |
Lesus
|
5. uname Command"uname"command isUnix Nameshort for. Displays machine name, OS and kernel details.
Note: unameshows kernel type, uname -ashows detailed info. Aboveoutputdetailsuname -a
6. history Command“history”command is the history. It shows the history of all commands executed in the terminal.
Note: Pressing “CTRL + R” allows you to search through previously executed commands, and it can auto-complete as you type.
|
Lesus
|
7. sudo Command“sudo”(super user do)command allows authorized users to execute superuser or other user commands. Through thesudoerslist security policy to specify.
Note:sudo allows users to borrow superuser privileges, whereas"su"command actually allows users to log in as superuser. Thereforesudo比susafer。
8. mkdircommand “mkdir”(Make directory)command creates a new directory at the named path. However, if the directory already exists, it returns an error message"cannot create directory, directory already exists"("cannot create folder, folder already exists")
Note: Directories can only be created in directories where the user has write permission.mkdir: cannot create directory`tecmint`, because the file already exists. (In the output abovedon’t be confused by the fileconfused, remember what I said at the beginning-在linuxin Linux, files, folders, drives, commands, scripts are all treated as files) |
Lesus
|
9. touch Command“touch”command stands for updating file access and modification times to the current time.touchcommand only creates the file if it does not exist. If the file already exists, it updates the timestamp but does not change the content.
Note:touch canis used to create non-existent files in directories where the user has write permission. 10. chmod Command“chmod”command is for changing file mode bits.chmodchanges each given file, folder, script etc. according to the requested mode(permissions). There are 3 types of permissions in files (folders or other, for simplicity, we’ll use file):
So if you want to give a file read-only permission, set it to'4';write-only permission, set to'2';execute-only permission, set to1; read-write permission, that is4+2 = 6, and so on. Now you need to set permissions for 3 types of users and groups. The first is the owner, then the group the user belongs to, and finally other users.
hererootpermissions are rwx(Read, write and execute permissions), To change its permissions, providing read, write, and execute permissions for the owner, the group, and other users.
All three have only read and write permissions.
The owner has read, write, and execute permissions, while the group and other users have only execute permissions.
Note: For system administrators and users, this command is one of the most useful commands. In a multi-user environment or on a server, if a file is set to be inaccessible for a certain user, this command can solve it. If wrong permissions are set, it may provide unauthorized access. |
Lesus
|
11. chown Command“chown”command changes file owner and group. Every file belongs to a user group and a user. In your directory, using"ls -l",you will see something like this.
Here, the directoryBinarybelongs to user"server",and user group"root",while directory"Desktop"belongs to user“server”and user group"server" “chown”command is used to change file ownership, so it is only used to manage and provide file user and group authorization.
Note:“chown”changes ownership of the given file to the new owner or existing user or user group. |
Lesus
|
12. apt CommandDebianseries with“apt”command as the foundation,“apt”representsAdvanced Package Tool。APTis aDebianseries systems (Ubuntu,Kubuntuetc.) developed advanced package manager, inGnu/Linuxon the system,it will automatically and intelligently search, install, upgrade, and resolve dependencies for packages.
Note: The above commands will cause system-wide changes, so root password is required (look for the prompt "#" instead of “$”). Compared to the yum command, Apt is more advanced and intelligent. As the name suggests,apt-cacheis used to search whether a package contains sub-packagesmplayer, apt-getis used to install and upgrade all installed packages to the latest version. aboutapt-get 和 apt-cacheFor more information on the command, see 25 APT-GET and APT-CACHE Commands |
Lesus
|
13. tar Command“tar”command stands for tape archive(Tape Archive), useful for creating archives of files and extracting them.
Note: "tar.gz"means usinggziparchive,“bar.bz2”usebzipcompression, which compresses better but is slower. learn more"tar command"for examples, see 18 Tarnaming examples 14. cal Command“cal”(Calender), it is used to display the month of the current or any year in the future or past.
displays a past month, February 1835
displays a future month, July 2145.
Note: You don’t need to adjust the calendar backwards50years, no complex calculation needed for your birth date or when your birthday falls,[because its smallest unit is month, not day]。 |
Lesus
|
15. date Command“date”command prints the current date and time to standard output, and can also be customized.
Note: This command is very useful in scripts, and time and date based scripts are even better. Moreover, changing the date and time in the terminal makes you look more professional!!! (Of course you need root privileges to operate this, as it is a system-wide change) 16. cat Command“cat”stands for concatenate (Concatenation), joining two or more text files or printing file contents to standard output.
Note:“>>”和“>”calls the append symbol. They are used to append to files instead of displaying on standard output.“>”symbol will delete existing files and create a new one. Therefore for safety reasons, it is recommended to use“>>”, which writes to files without overwriting or deleting. |
Lesus
|
|
Before diving deeper, I must let you know about wildcards (you should know wildcards, they appear in most TV talent shows). Wildcards are a feature of the shell, and make any GUICompared to a file manager, it makescommand line more powerful! As you can see, in a graphical file manager, if you want to select a large group of files, you usually have to use your mouse to select them. This may seem simple, but in fact, this situation is quite frustrating! For example, suppose you have a directory with many, many files of various types and subdirectories, and you decide to move all HTML files whose filenames contain the word “Linux” to another directory. How do you easily accomplish this? If the directory contains a large number of differently named HTML files, your task is huge, not simple. In the Linux CLI, this task is as simple as moving just one HTML file, thanks to shell wildcards. These are special characters that allow you to select filenames matching certain character patterns. It helps you select, even among a large number of filenames with only a few characters, and in most cases, it is simpler than using a mouse to select files. Here is a list of commonly used wildcards:
! called NOT, with'!'the inverted string is true For more, readLinux cat command examples 13 Linux cat Command Examples |
Lesus
|
17. cp Command“copy” means to copy. It copies a file from one place to another.
Note: cp,在shellis one of the most commonly used commands in scripts, and it can use wildcards (described in the previous section) to customize file copying. 18. mv Command“mv”command moves files from one location to another.
Note:mv command can use wildcards.mvUse with caution, as moving system or unauthorized files can not only cause security issues but may crash the system. 19. pwd Command“pwd”(print working directory), displays the full path of the current working directory in the terminal.
Note: This command is not frequently used in scripts, but for beginners, when connecting tonuxafter a long timein the terminallosing track of the path,this is absolutely a lifesaver. |
Lesus
|
20. cd Command
Finally, the frequently used“cd”command stands for change directory. It changes the working directory in the terminal for execution, copying, moving, reading, writing, etc.
1 |
root@tecmint:~# cd /home/user/Desktop |
1 |
server@localhost:~$ pwd |
2 |
3 |
/home/user/Desktop |
Note: When switching directories in the terminal,cdcomes into its own.“cd ~”changes the working directory to the home directory, and is very useful when you find yourself lost in the terminal.“cd ..”switch from the current working directory to(of the current working directory)parent directory。
These commands will definitely make you comfortable on Linux. But this is not the end. Soon, I will write some other useful commands targeted at intermediate useruseful commands. For example, if you are proficient with these commands, congratulations, you have leveled up from beginner to intermediate user. In the next article, I will introduce commands like“kill”,"ps","grep"and more, stay tuned, I won’t let you down.

