Saturday, 6 May 2017

The 10 most important Linux commands for beginners

1. Clear: clean up the input window
You have lost the overview after countless inputs and just want to have the input window simply blank again: Tap "clear". Alternative: CTRL + L.
2. Whoami - who am I - and Who
You are not sure what your username is, where you are logged in: "whoami" provides the answer (alternatively, you can also type "who -m".) Whoami makes sense when you are often between different users or root And the user name does not appear in the prompt.
3. pwd: Where am I?

You have lost your bearings and do not know which directory you are in. The bash "pwd" command will help and display your current directory.
4. df: Show file system and disk space
The "df" command displays the file system including the memory allocation. So you can see for example at a glance, how many hard disks are available in your Linux-PC and how much space is still available. You will also see how each drive is mounted in the directory hierarchy. To increase the readability of the output, always type "-h" with "-h", ie, "df -h": The memory location is displayed in Mbyte or Gbyte and not in bytes. With "df -T", the command names the file system for each partition and volume. 
If you type df together with the name of a directory, you will see only the data of the partition where the directory is located. 
5. Passwd: Change password
Even a password, which is still so secure, should be changed from time to time. And in particular change a password preset by the manufacturer into a separate password. Please enter "passwd". Linux then prompts you to enter your previous password (in our example, a Unix password). The input is invisible. Then you are prompted to enter a new password. This is repeated again - both inputs are also made invisible. And your new password (please do not write it down on a post-it and stick it to the screen).
Caution: Linux is case-sensitive. Numbers and bindings and underlines are allowed, but commas or semicolons are not allowed.
By the way, the passwords saves Linux encrypted in the / etc / shadow file.
With normal user rights you can only change your own password with passwd. With root privileges you can also change the passwords of all other users: "passwd username" is the command. However, the old password does not have to be specified. With "passwd -l" (l stands for lock), root can deactivate an account. The reactivation takes place with "passwd -u" (u stands for unlock). 
6. ls: Show Directory
With "ls", you can view all files and directories in the directory where you are currently located. In our example (an Ubuntu system) directories are marked blue, files in white color. You can change the directory with the "cd" command in any directory displayed (see below). Hidden files and directories are marked with a prefix ".".
If you want to know more about the existing files and directories, type "ls -al". Then, Linux will give you the file type (for example, "-" for files, "d" for directory) for each file and directory, access rights information, the number of hardlinks (that point to the file), and a file owner To the file size (in bytes) and to the last modification date with time, and finally the file or directory name. The option "a" (for "all") also ensures that system directories are displayed. The "l" (for long) provides the detailed, long-term output, with each file and directory in its own line.
7. cd: Change directory
Press "cd .." to move to the next directory. If you got an overview of the existing directories with "ls", you can change to DIRECTORYNAME / cd in any directory. You must pay attention to the exact spelling of the directory name. However, the tab key makes the entry easier: Type only the first letter (s) of the desired directory name, and then press the TAB key to make Linux complete the name.
The cd command without parameters lets you switch to your home directory.
Important: In addition to relative paths (which you enter in the directory hierarchy hierarchy depending on your current "location"), you can also enter absolute paths: Always start from the root directory, for example: cd / home / Username /Documents.
8. cp: Copy and rename
Use "cp" to copy files and entire directories in one go. An example of copying a single file to another directory is "cp filename_file". If you specify a non-existing name instead of the target directory, the file is renamed.
Use "cp -r source directory target directory" to copy a complete directory, including the hidden files and subdirectories.
9. rm: Delete files
Use "rm" to delete only files. Rm *. ~ Deletes all backup files in the current directory. 
Directories are only deleted with "rm" if you set the "-r" option behind them. The "r" stands for "recursive": all directories and files are then deleted downwards from the input location of the user. And even directories, even if they still contain files or other directories and thus are not empty.
This deletion occurs on some systems with request, on others, but also without further inquiry, so you can easily inadvertently transfer important files and directories into the Nirvana.
Caution: Use the command "rm -r f " to sweep all files and directories down from your hard drive location explicitly without asking the Linux system again. The "f" stands for "force": Also read-only files are deleted without request.
Enter this command at the top level, ie root alias "/", so delete your entire Linux system if you are logged in as root. But even if you enter this command as a normal user, you will destroy at least all the files and directories that belong to you.
If you want to delete files whose filenames contain special characters, you must set the special characters between simple apostrophes, for example: rm '#' * deletes all files in the directory beginning with #. 
10. Cat: Quickly display or create a text file
Want to quickly view the contents of a text file? Then type "cat filename". The terminal window then displays the contents of the text file. For text formats that contain complex formatting characters and control characters, however, the output is sometimes confusing. For an initial overview, the output of cat can be quite sufficient and simple txt files can be displayed even with it flawlessly.

No comments:

Post a Comment