• Tidak ada hasil yang ditemukan

PDF The Linux Commands Handbook - TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI

N/A
N/A
Nguyễn Gia Hào

Academic year: 2023

Membagikan "PDF The Linux Commands Handbook - TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI"

Copied!
135
0
0

Teks penuh

Microsoft has an official Windows Subsystem for Linux that you can (and should!) install on Windows. You can set the system to run any shell, for example I use the Fish shell. You can then use the man page to explore all the different options and parameters you can use in the command.

If the last parameter is a folder, the file in the first parameter path is moved to that folder.

Hard links

If you delete the original file, the link will still contain the original file content as it is not removed until there is a hard link pointing to it.

Soft links

Now whenever you edit either of those files, the content will be updated for both. Now if you delete the original file, the links will be broken and the shell will tell you "No such file or directory" if you try to access it:.

The tar command is used to create an archive that groups multiple files into a single file.

To make it permanent, add it to the shell configuration, which could be ~/.bashrc or. Be careful with quotes if you have variables in the command: using double quotes resolves the variable at definition time, using single quotes resolves it at invocation time. You can only add a number to non-blank lines using -b , or you can also remove all the multiple blank lines using -s.

When the file is modified by someone else, such as from another program, you can see the changes live. By default this does not happen and you only see the file version at the time you opened it. You can open multiple files and navigate through them using :n (to go to the next file) and :p (to go to the previous).

Bytes in ASCII characters are equivalent to characters, but with non-ASCII charsets the number of characters can vary because some characters can take multiple bytes, for example it happens in Unicode.

One very useful thing is to tell grep to print 2 lines before, and 2 lines after the matching line, to give us more context. Another thing you may find very useful is to reverse the result, excluding the lines that match a specific string, by the -v option:.

Use the --ignore-case option to sort case insensitive, and the -n option to sort using numerical order.

If you reverse the order of the files, it will tell you that the second file is missing line 3 of its contents. There are many more options that you can explore on the man diff man page.

We can do some cool stuff when it comes to interacting with shell features.

It is quite common to need to change the ownership of a folder, and recursively all the files it contains, plus all subfolders and the files contained within them.

You can apply the same permissions to multiple personas by adding multiple letters for the . If you are editing a directory, you can apply the permissions to any file in that directory using the -r (recursive) flag. Numerical arguments are faster, but I find them hard to remember if you don't use them every day.

Other users belonging to the same group ( g ) have read and execute rights, just like all other users ( o. You can also specify a file or folder name to get information about the specific volume it resides on: .

This is crucial if you want to refer to this process in another command, for example to kill it. It is common to have a + to indicate that the process is in the foreground on its terminal. A quick guide to the above command used to list the processes running in real time.

The top command is used to display dynamic real-time information about running processes in the system. A lot of information is given to us: the number of processes, how much is running or sleeping, the system load, the CPU usage, and much more. By default, as you can see from the %CPU column highlighted, they are sorted by the CPU being used.

INT means interrupt, and it sends the same signal used when we press ctrl-C in the terminal, which usually terminates the process. KILL is not sent to the process, but to the operating system kernel, which immediately stops and terminates the process. STOP is not sent to the process, but to the operating system kernel, which immediately stops (but does not terminate) the process.

You can continue running the command in the background so it will continue to run but not prevent you from doing other things in the terminal. It could also say bg without any option, since the default selected job is no. 1 on the list. You can also specify which job you want to continue in the foreground by passing the job number, which can be obtained using the jobs command.

One of the most interesting things here is that for aliases it will tell you what is aliasing to. You can see the ll alias, in the case of Bash and Zsh, but Fish provides it by default, so it will tell you it's a built-in shell function.

One of the most useful in my opinion, especially when starting to learn xargs, is -p. The -n option lets you tell xargs to do one iteration at a time, so you can commit them individually with -p. It allows you to get an exit to the enclosure and then you can do different things.

At this point you can navigate the file, but you can't add content to it (and be careful which keys you press as they could be commands). If you follow it with e instead of w, the white space before the next word is preserved. Press d followed by $ to delete the entire line from where the cursor is, all the way to the end.

If you're on Linux, there's no problem, but macOS doesn't ship programs that use GPLv3, and every built-in UNIX command that's been updated to GPLv3 hasn't been updated. Although there is a small problem with the commands I've listed so far, in this case, using a 2007 version of emacs is not quite the same as using a version with 12 years of improvements and changes. To fix this, run brew install emacs and running emacs will use the new version from Homebrew (make sure you have Homebrew installed).

I encourage you to open Emacs and press ctrl-h r to open the built-in manual and ctrl-h t to open the official tutorial.

You can see the name of the terminal used and the time/day the session was started. While logged into the terminal shell with one user, you may need to switch to another user. For example, you are logged in as root to perform some maintenance, but then you want to switch to a user account.

If you are logged in as a user, running su without anything else will prompt you for the root user password, as this is the default behavior. When you're done, pressing exit in the shell will close that shell and switch back to the current user.

Sometimes this is done on purpose, to "hide" the server or just to reduce the load. It is useful to ping a host to know if the host is reachable (if it implements ping) and how far it is in relation to how long it takes to get back to you. Usually the closer the server is geographically, the less time it will take to get back to you, for simple physical laws that cause a longer distance to introduce more delay in the cables.

For each router we can see 3 tries, which means traceroute by default tries 3 times to give you a good indication of the time it takes to reach it.

Then you set chmod u+x script.sh and run this script with ./script.sh , the echo $TEST line will print nothing. It is common to use export when creating new variables this way, but also when creating variables in the .bash_profile or .bashrc.

That's why I usually use a website to help me generate it without errors: https://crontab-generator.org/. You select a time interval for the cron job and type the command to run. You can remove a cron job by running crontab -e again, removing the line and exiting the editor:.

On macOS, you can also use the sw_vers command to print more information about the macOS operating system. The kernel is the "core" of the operating system, while the operating system as a whole is called macOS. In Linux, Linux is the core, GNU/Linux would be the Operating System name, although we all refer to it as "Linux".

The env command can be used to pass environment variables without setting them to the external environment (the current shell). You can also run the command clearing all environment variables already set, using -i. In this case you will get an error saying env: node: No such file or directory because the node command is not reachable, since the PATH variable used by the shell to look for commands in common paths is not set.

Conclusion

Referensi

Dokumen terkait

Depending upon what you wish to emphasize in the sentence, you may want to revise it using the active voice.. Article Error You may need to use an article before this