- The explanation of the programs and commands is based on my understanding of them. However, I have contrasted them using the program
manand the flag--helpas a reference in order to give the simplest yet most accurate explanation to each one. Every external reference has been indicated in its respective part. - You might be missing some programs/flags. I am listing the ones that I have used so far, so I might be overlooking some useful utilities. Feel free to improve the list with the addition of more, with their respective explanation.
- If you have any trouble finding out what a program does, simply use
man [PROGRAM],info [PROGRAM]orwhatis [PROGRAM]to retrieve more information about it. - Some commands are written like this one:
rm [-r|--recursive]. That means that the commandsrm -randrm --recursiveare both possible inputs. If the description of a command like this does not specify the difference between them, it is because there is none. - In brackets and in uppercase (for example,
[FILE]), it is specfied what type of argument is needed for a certain command. For example, a real use ofcat [FILE]would becat foo.txt. - If you want to exit the execution of a command and typing and executing
exitdoes not work, press Ctrl + C to interrrupt it. - Bear in mind that some flags can be combined, depending on their function. For example,
ls -aandls -lcan be merged asls -a -lor, even better, asls -al. - You will have to be root or superuser in order to execute some of the commands listed. Check whether you are the root user by executing
whoamior, if you are not, make sure to addsudoat the beginning of the given command. You can also executesudo su -for log in as the root user. - On the left side of the CLI (Command Line Interface), you will notice something like this:
jc@jc:~$.jc- Current userjc- Group to which the user belongs~- Current path.~is the user's home directory./is the very top of the filesystem.$- States that the user is logged in as a normal user. It could also be#, which would mean that the user is the system administrator (root). - Whenever you encounter a
…in a command, bear in mind that its meaning is that multiple arguments can be passed to it. For example,cat [FILE] …means that more files can be passed to it, like this:cat foo.txt bar.txt.
Concepts:
- Command: A Linux command is a program or utility that runs on the command line. A command line is an interface that accepts lines of text and processes them into instructions for your computer. Any graphical user interface (GUI) is just an abstraction of command-line programs.
- Argument: It is an input (usually, a file or a directory) given to a command to run a process that depends on the given input. For example, in the command
cat foo.txt, the argument is foo.txt. - Flag: You will see them as a dash plus a letter (e.g. -r) or a double dash plus a word (e.g. --recursive). They provide extra information to the program to change its functionality. To see all the flags available in a program, one can use the flag
helplike this:[COMMAND] --help. Additionally,manandinfowill provide an extensive explanation of what the program does. - Wildcard: Placeholder represented by a single character, such as an asterisk, which can be interpreted as a number of literal characters or an empty string. It is often used in file searches so the full name need not be typed. E.g.
*.txt. - Pipes:
|, known as pipes, redirect output to another program. They route the output of the command on the left of the|and passes it to the command on the right of the|. E.g.find /documents -name '*.txt' -printf0 | wc -l --files0-from=-.
-
whatis [PROGRAM]for printing a single-line description of the given program. -
man [PROGRAM]for retrieving a detailed description of what the program do along with its flags. -
info [PROGRAM]for retrieving the info documents of the program. It is good for contrasting some information found with themanprogram. -
[PROGRAM] --helpfor printing in the console the flags that the program accepts. -
For instance, open the terminal and run
man rmorinfo rm.manwill tell you what thermprogram does, how it works, and the available flags/options. Forrm, the-rflag means:-r, -R, --recursive remove directories and their contents recursivelyYou can see that there are multiple ways to set this flag as well. You could run
rm -r,rm -R, or evenrm --recursive, all will do the same thing. However, each program has its own flags and, for example,-Rdoes not do the same with the commandrmas it does with the commandls, so make sure to check the documentation for each program when working with them. Reference.
datefor showing the current date and time../[EXECUTABLE FILE]for running an executable. It is not a command by itself but it lets your shell run an executable file with any interpreter installed in oyr system directly from the terminal, without the need of specifying said interpreter. We can run a Bash file as well as a Python script indistinctly. E.g../python_script.py. Remember that the file needs to have thexpermission (explained below).clearfor bringing the command line on top of the computer terminal.exitfor exiting the execution of a program (not all though) and/or exiting the shell currently running.echo "[TEXT]"for displaying a defined text in the terminal. Its primary usage is to print environmental variables inside those messages such asecho "Hey $USER"historyfor displaying an enumerated list with the commands used in the past.!!for repeating the previously executed command.uptimefor showing how long the system has been running.which [PROGRAM]for retrieving the directory in which a program is installed.
unamefor printing the name of the kernel. Stands for Unix name.uname [-a|--all]for printing all available information. E.g.Linux jc 5.4.0-107-generic #121-Ubuntu SMP Thu Mar 24 16:07:22 UTC 2022 aarch64 aarch64 aarch64 GNU/LinuxLinux- Kernel name.jc- Hostname.5.4.0-107-generic- Kernel release.#121-Ubuntu SMP Thu Mar 24 16:07:22 UTC 2022- Kernel version.aarch64- Machine hardware name.GNU/Linux- Operating system name.uname [-s|--kernel-name]for printing the kernel name. Output example:Linux. Same as executinguname.uname [-n|--nodename]for printing the network node hostname. Output example:jc.uname [-r|--kernel-release]for printing the kernel release. Output example:5.4.0-107-generic.uname [-v|--kernel-version]for printing the kernel version. Output example:#121-Ubuntu SMP Thu Mar 24 16:07:22 UTC 2022.uname [-m|--machine]for printing the machine hardware name. Output example:aarch64.uname [-p|--processor]for printing the processor type. Output example:aarch64.uname [-i|--hardware-platform]for printing the hardware platform. Output example:aarch64.uname [-o|--operating-system]for printing the operating system. Output example:GNU/Linux.
neofetchis a command-line system information tool written displays information about your operating system, software and hardware in an aesthetic and visually pleasing way. It has to be installed viaapt, like this:sudo apt install neofetch.
Example
.-/+oossssoo+/-. jc@jc -:+ssssssssssssssssss+:- ----- -+ssssssssssssssssssyyssss+- OS: Ubuntu 20.04.4 LTS aarch64 .ossssssssssssssssssdMMMNysssso. Host: QEMU Virtual Machine virt-6.2 /ssssssssssshdmmNNmmyNMMMMhssssss/ Kernel: 5.4.0-107-generic +ssssssssshmydMMMMMMMNddddyssssssss+ Uptime: 1 day, 4 hours, 58 mins /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/ Packages: 1659 (dpkg), 4 (snap) .ssssssssdMMMNhsssssssssshNMMMdssssssss. Shell: bash 5.0.17 +sssshhhyNMMNyssssssssssssyNMMMysssssss+ Resolution: 1440x837 ossyNMMMNyMMhsssssssssssssshmmmhssssssso DE: GNOME ossyNMMMNyMMhsssssssssssssshmmmhssssssso WM: Mutter +sssshhhyNMMNyssssssssssssyNMMMysssssss+ WM Theme: Adwaita .ssssssssdMMMNhsssssssssshNMMMdssssssss. Theme: Yaru [GTK2/3] /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/ Icons: Yaru [GTK2/3] +sssssssssdmydMMMMMMMMddddyssssssss+ Terminal: gnome-terminal /ssssssssssshdmNNNNmyNMMMMhssssss/ CPU: (4) .ossssssssssssssssssdMMMNysssso. GPU: 00:01.0 Red Hat, Inc. Virtio GP -+sssssssssssssssssyyyssss+- Memory: 851MiB / 3916MiB -:+ssssssssssssssssss+:- .-/+oossssoo+/-.
shutdown nowfor shutting down the system now.shutdown [-r|--reboot] [TIME]for rebooting the system at a specific time.shutdown [-p|--poweroff] [TIME]for powering off the system at a specific time.shutdown [HH:MM]for shutting down the system at a specific time.shutdown -cfor canceling a scheduled shutdown.
service [NAME] [ACTION]for [status|stop|start|restart] a service. Each possible input will do different things, as one can expect based on their name. E.g.sudo proftpd status.htopfor opening an interactive process viewer that lets you manage your machine's resources directly from the terminal. In most cases, it isn’t installed d by default, so make sure to read more about it on its download page.psfor displaying your currently active processes. Stands forprocess status.PID TTY TIME CMD 7480 pts/1 00:00:00 bash 7486 pts/1 00:00:00 pskill [PID]for killing a process with the given Process Identifier (PID).
sudo [COMMAND]for executing a command as superuser. Stands for superuser do.sudo su -for logging in as a root user.sustands for switch user.whoamifor showing the name of the current user logged-in.
passwdfor changing the password of the current user logged-in.passwd [USER]for changing the password of the given user.passwd -gfor changing the password of the current group to which the current user logged-in belongs.passwd -g [GROUP]for changing the password of the given group.passwd -e [USER]for forcing users to change their password the next time they log in.passwd -l [USER]for locking the user's passwordpasswd -u [USER]for unlocking the user's password.
aptstands for Advanced Package Tool, which is a collection of tools used to install, update, remove, and otherwise manage software packages on Debian and its derivative operating systems, including Ubuntu and Linux Mint.. Consists of some of the most widely used features from apt-get and apt-cache, leaving aside obscure and seldom used features. It can also manage apt.conf file.. It can be considered as an abstraction of those two commands.
Notice that you will have to execute all these commands with sudo or as root user.
apt install [PACKAGE]for installing a package.apt reinstall [PACKAGE]for reinstalling a package.apt remove [PACKAGE]for removing a package.apt purge [PACKAGE]for removing a package along with its configuration.apt upgrade [PACKAGE]for upgrading a certain package (if available for upgrading).apt show [PACKAGE]for showing all details of a package, such as the author, the version and the description.apt updatefor refreshing repository index.apt upgradefor upgrading all packages available for upgrading (if any).apt full-upgradefor upgrading all packages and installing, removing and upgrading packages as apt deems necessary.apt autoremovefor removing unwanted packages.apt list --upgradablefor listing all packages available for upgrading.apt list --installedfor listing all installed packages.apt edit-sourcesfor changing the source of the packages.apt-getandapt-cachehave been replaced byaptbut you might see them listed in some old tutorials. As you might think due to the statements at the beginning, it is prefered to useaptoverapt-getandapt-cachedue to its abstraction and simplification. Here is an interesting article explaining in detail the differences betweenaptandapt-get/apt-cache.
-
Beyond knowing the commands, which is important, it is vital to know the information displayed by some of these commands. For example, if we execute
ls -l, something like the line below will be displayed, depending on your files, computer, permissions… The following explanation has been taken from here with slight changes made by me:-rwxrw-r-- 10 root root 2048 Jan 13 07:11 afile.exe ?UUUGGGOOOS 00 UUUUUU GGGGGG #### MON DD XX:XX FILENAME ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ └ Filename | | | | | | | | | └-------------- Time of last modification | | | | | | | | └--------------------- File size. Some versions and/or command line flags will list the number of blocks used instead of the number of bytes. A filesystem with a block size of 1024 bytes will list all sizes up to 1024 bytes as 1, meaning 1 block is used; from 1025 to 2048 as 2, using 2 blocks; and so on. However, listing block sizes by default (without explicitly using a command line option) is rare on most modern Unix machines | | | | | | | └-------------------------- Group Name (for example, Users, Administrators, etc) | | | | | | └--------------------------------- Owner's name | | | | | └---------------------------------------- Number of [hard links](https://www.cbtnuggets.com/blog/certifications/open-source/linux-hard-links-versus-soft-links-explained#:~:text=In%20Linux%20systems%2C%20the%20data%20structure%20that%20does%20the%20actual%20storing%20of%20information%20is%20called%20an%20Inode.%20A%20hard%20link%20is%20a%20file%20all%20its%20own%2C%20and%20the%20file%20references%20or%20points%20to%20the%20exact%20spot%20on%20a%20hard%20drive%20where%20the%20Inode%20stores%20the%20data.) associated with the file | | | | └--------------------------------------------- Alternative access (blank means none defined, anything else varies) | └--└--└----------------------------------------------- Read, write and special access modes for [U]ser, [G]roup, and [O]thers (everyone else) └------------------------------------------------------- File type flag. This is a normal file, so the type is **-**. It could be of type **l**, among others, which would mean that the file is a symbolic link (a.k.a. shortcut). **d** is for directories. [Here](https://linuxconfig.org/identifying-file-types-in-linux) is more information about file typesIf we wanted to print the info of a directory, we would get something like this:
drwxrw-r-- 16 root root 2048 Feb 21 10:57 downloads ?UUUGGGOOOS 00 UUUUUU GGGGGG #### MON DD XX:XX DIRECTORY ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ └ Directory name | | | | | | | | | └-------------- Time of last modification | | | | | | | | └--------------------- File size. Some versions and/or command line flags will list the number of blocks used instead of the number of bytes. A filesystem with a block size of 1024 bytes will list all sizes up to 1024 bytes as 1, meaning 1 block is used; from 1025 to 2048 as 2, using 2 blocks; and so on. However, listing block sizes by default (without explicitly using a command line option) is rare on most modern Unix machines | | | | | | | └-------------------------- Group Name (for example, Users, Administrators, etc) | | | | | | └--------------------------------- Owner's name | | | | | └---------------------------------------- The default link count of any directory is 2. The extra count is because for every directory created, a link gets created in the parent directory to point to this new directory. In order to know how many subdirectories has a directory, the operation would be the number of link counts minus 2. In this case, we can see that we have 14 subdirectories in the downloads directory | | | | └--------------------------------------------- Alternative access (blank means none defined, anything else varies) | └--└--└----------------------------------------------- Read, write and special access modes for [U]ser, [G]roup, and [O]thers (everyone else) └------------------------------------------------------- Type flag. **d** stands for directory, which is the only available type for a directory (exceptions may apply)
Commands:
lsfor displaying files/directories of a directory. Stands for list.ls -lfor displaying all files information in a directory. Output:-rw-rw-r-- 1 jc jc 192 abr 13 14:18 foo.txt -rw-rw-r-- 1 jc jc 0 abr 13 14:56 barls -l [FILE]for displaying all the information of the specified file. Output if the input isls -l foo.txt:-rw-rw-r-- 1 jc jc 192 abr 13 14:18 foo.txtls -d????ls [-a|--all]for displaying the name of the directories and files in a directory, including the current directory (.) and the parent directory (..). Example:. .. bar foo.txtls [-al|-a -l]for displaying all information of the files/directories in a directory, including the current directory (.) and the parent directory (..).drwxr-xr-x 2 jc jc 4096 abr 13 14:56 . drwxr-xr-x 16 jc jc 4096 abr 8 14:16 .. -rw-rw-r-- 1 jc jc 0 abr 13 14:56 fools -ltfor displaying all information about files/directories in date order (new to old).ls -ltrfor displaying all information about files/directories in reverse date order (old to new).lscan also be combined withheadandtail(explained below) like this:ls -ltr | tail -3. That would show the 3 most recently updated files.pwdfor showing the path of the current directory. Stands for print work directory.
cat [FILE] …for displaying an entire file. Stands for concatenate.cat > [FILE]for creating a new file along with its content. Similar totouch. E.g:
If we want to save the file, then press Ctrl + D. If not, press Ctrl + C.jc@jc:~/Downloads$ cat > foo.txt I'm just a file :Dcat >> [FILE]for appending text at the end of a file.cat [-n|--number] [FILE]for displaying the line numbers next to each line in the terminal, including blank lines.cat [-b|--number-nonblank] [FILE]for displaying the line numbers next to each line in the terminal, excluding blank lines.cat [-s|--squeeze-blank] [FILE]for squeezing repeating blank lines into one.cat [FILE] | wc -cfor displaying the total number of characters in a file.cat [FILE 1] [FILE 2] … > [FILE 3]for concatenating the content of [FILE 1] and [FILE 2] in [FILE 3].cat [FILE] | head -[NUMBER]for outputing the first [NUMBER] of a file.cat [FILE] | tail -[NUMBER]for outputing the first [NUMBER] of a file.
more [FILE]for showing the content of a file. It is similar tocatbut, if the file is large, it will display the percentage opened of the file. For displaying more lines, it is necessary to press Enter.more -[NUMBER] [FILE]for limiting the number of lines showed.more -s [FILE]for squeezing repeating blank lines into one. Same ascat -s [FILE].more +/[STRING] [FILE]for printing the fragment in which the given string appears.
lessis an advanced version ofmore. It allows us to go backward and forward. Its commands are based invi, from whichlessdiffers in its speed, because it does not need to read the entire file before opening it. If the file is large, it will be divided into pages. The end of a page is marked by a:.- If we want to go a page forward, press F or Space. To go backward, press B.
- To close a file, press Q.
less [FILE]for opening a file.less [-n|-N] [FILE]for opening a file and showing line numbers.less -X [FILE]to avoid opening a file in a new screen. It will print the file in the command line instead, asmoredoes.less +F [FILE]for watching the file contents for changes. Useful when opening log files that are being written. Similar totail -f.
head [FILE]for showing the first 10 lines of a file.head -[NUMBER] [FILE]orhead -n [NUMBER] [FILE]for showing the first [NUMBER] lines of a file.tail [FILE]for outputing the last 10 lines of a file.tail -[NUMBER] [FILE] …ortail -n [NUMBER] [FILE]for showing the last [NUMBER] lines of a file. We can also execute[head|tail] -n [NUMBER] [FILE] …for printing the first/last line of each argument.[head|tail] [-f|--follow] [FILE]for watching the file contents for changes. It will print the first/last 10 lines of the file.
touch [FILE]for creating a new file. E.g.touch /etc/foo.txt.mkdir [DIRECTORY]for creating a directory. Stands for make directory.mkdir -p [DIRECTORY]for creating a subdirectory. It is super useful when we want to create the subdirectory of a directory that we have not created yet. E.g.mkdir -p /downloads/foo/barwherefoohas not been created yet.
mv [FILE] [DIRECTORY]for moving a file to a certain directory. Stands for move.mv [OLD FILE] [NEW FILE]for renaming a file. The[OLD FILE]is the file that will be renamed with a new name[NEW FILE]. E.g.mv foo.txt bar.txt
rm [FILE]for removing a file. Stands for remove.rm [-f|--force] [FILE]for forcing the removal of a file. Stands for remove.rm [-r|-R|--recursirve] [DIRECTORY]for removing a directory recursively. They all do the same.rm [-rf|-r -f|-R -f|--recursive --force] [DIRECTORY]for forcing the removal of a directory recursively. They all do the same.shred [FILE]for overriding the content of a file repeatedly to make it extremely difficult to recover.shred -u [FILE]for deleting the file after overriding it.
cp [FILE TO COPY] [NEW FILE]for copying a file. E.g.cp /downloads/foo.txt /documents/bar.txt. Stands for copy.cp [-r|-R|--recursive] [DIRECTORY TO COPY] [NEW DIRECTORY]for copying a directory.cp [-rT|-RT] [DIRECTORY TO COPY] [NEW DIRECTORY]for copying only the files and subdirectories but not the source directory.cp [FILE] [DIRECTORY]for copying a file into a given directory.cp [FILE|DIRECTORY 1] [FILE|DIRECTORY 2] … [FINAL DIRECTORY]for copying multiple files and directories at once to a specific directory. The last argumment must be the target directory.cp [-i|--interactive] [FILE|DIRECTORY] [FILE|DIRECTORY]for forcingcpto prompt for confirmation.cp [-n|--no-clobber] [FILE TO COPY] [NEW FILE]for not overwriting an existing file.cp [-u|--updating] [FILE TO COPY] [NEW FILE]for copying the file only if it is newer than the destination.cp [-p|--preserve] [FILE TO COPY] [NEW FILE]for preserving the file mode, ownership and timestamps from the old file to the new one.cp [-v|--verbose] [FILE|DIRECTORY TO COPY] [NEW FILE|DIRECTORY]for printing verbose output.
grep [PATTERN] [FILE]for printing the occurences of the pattern in the file. E.g.grep "chair" foo.txt. Stands for global regular expression print. Bear in mind that, if we executegrep "ng" foo.txt, a few possible matches are running, searching, falling… If you want to look for a matching word, see the flags-wor--word-regexp.grep [-r|--recursive] [PATTERN] [DIRECTORY]for searching the pattern in a directory, skipping the symlinks.grep [-R|--dereference-recursive] [PATTERN] [DIRECTORY]for searching the pattern in a directory, following the symlinks.grep [-c|--count] [PATTERN] [FILE]for retrieving the number of occurences of the given pattern found in the file.grep [-v|--invert-match] [PATTERN] [FILE]for displaying the lines that do not match the pattern.grep [-l|--files-with-matches] [PATTERN] [FILENAME WITH WILDCARD]for showing only the names of the files in which the pattern is found. E.g.grep -l "hello world" *.conf.grep [-i|--ignore-case] [PATTERN] [FILE]for executing a case insensitve search.grep [-w|--word-regexp] [PATTERN] [FILE]for retrieving an exact match of the pattern.grep [-n|--line-number] [PATTERN] [FILE]for showing the match along with the line number in which it has been found.- Bear in mind that we can use regular expressions instead of hardcoded strings. Check this link out for more information.
Before getting into more details, it is important to know the different types available:
f: a regular filed: directoryl: symbolic linkc: character devicesb: block devicesp: named pipe (FIFO)s: socket
The most common are f and d.
By name
find [DIRECTORY] -type f -name '[PATTERN]'for searching a file by name. E.g.find /documents -type f -name 'foo.txt'. The name of the file can be surrounded by either single or double quotes as well (which is prefered to avoid errors).find [DIRECTORY] -type f -iname '[PATTERN]'for searching a file by name, regardless of its case. E.g.find /documents -type f -name 'foo.txt'.
By extension
find [DIRECTORY] -type f -name '*.[EXTENSION]'for searching files by their extension. E.g.find /documents -type f -name '*.txt'.find [DIRECTORY] -type f -name '*.[EXTENSION]'for searching files by their extension. E.g.find /documents -type f -name '*.txt'.
By size
find [DIRECTORY] -type f -size [NUMBER][UNIT]for searching a file that fits the size criteria. E.g.find /downloads -type f -size 1024cwill look for files of exactly 1024 bytes in the downloads directory.find [DIRECTORY] -type f -size [+|-][NUMBER][UNIT]for searching a file above or below the size criteria.
Examples:
find . -type f -size +1Mfor searching a file in the current directory above with a size above 1 Megabytes.find . -type f -size -1kfor searching a file in the current directory above with a size below 1 Kilobytes.find . -type f -size +10M -size 100Mfor searching a file in the current directory in the range of 10 Megabytes and 100 Megabytes.
The units can be:
b: 512-byte blocks (default)c: bytesw: two-byte wordsk: KilobytesM: MegabytesG: Gigabytes
By date
find [DIRECTORY] -name [FILE] -mtime [NUMBER OF DAYS]for searching modified files in the last [NUMBER OF DAYS]. E.g.find /downloads -name "*.jpg" -mtime 5.- We can use
[+|-]as well, just like this:find /music -mtime +30 -daystart. This will list all files in the music directory that were modified 30 or more days ago.
By permission
find /var/www/html -perm [PERMISSION IN OCTAL]for searching by permission. E.g.find /pictures -perm 644.- In front of the [PERMISSION IN OCTAL], we can place a
-for excluding the permission or a/, which means that, at least, one category (user, group, or others) must have the respective bits set for a file to match. E.g.find . -perm /222will match all the files with write permissions set for either user, group, or others.
By owner
find [DIRECTORY] -user [USER]for finding files owned by a particular user.find [DIRECTORY] -group [USER]for finding files owned by a particular group.
**Find and execute a file
find [FILE|DIRECTORY] -type [TYPE] -exec [COMMAND]for executing a command in the given file/directory.
Find and delete a file/directory
find [FILE|DIRECTORY] -type [TYPE] [PATTERN] -deletefor deleting a given file/directory. Bear in mind thatfindcan only delete empty directories. If you want to delete a directory with content, userm [-r|-R|--recursive].
Reverse search
- The
-notoption allows us to find files/directories that do not contain the given pattern. E.g.find /documents -type f -not -name 'foo.txt'will retrieve those files that are not named asfoo.txt.
wc [FILE] …for showing the number of characters, lines, size and name of the file(s). Output example if we executewc foo.txt:37 207 1000 foo.txt.wc < [FILE] …for showing the number of characters, lines and size of the file(s).wc [-l|--lines] [FILE] …for printing the number of lines of the file(s).wc [-w|--words] [FILE] …for printing the number of words of the file(s).wc [-m|--chars] [FILE] …for printing the number of characters of the file(s).wc [-c|--bytes] [FILE] …for printing the number of bytes of the file(s).wc [-L|--max-line-length] [FILE] …for printing the length of the longest line.wc [FLAG] --files0-from=Ffor reading an input from the files specified by NUL-terminated names in file F. If F is - then read names from standard input. NUL-terminated filenames are the output of another program. For example, thefindutility normally returns results separated by newlines but one can use the-printf0flag to have it return results separated by NUL. This is useful when passing filenames with spaces to another program, likefind, which treats white space a separators by default.
Output example if we executefind /documents -name '*.txt' -printf0 | wc -l --files0-from=-:5 /documents/foo.txt 2 /documents/bar.txt 7 total
vi [FILE]for opening a file with Vi. Stands for Visual.vim [FILE]for opening a file with Vim. Stands for Vi improved.nano [FILE]for opening a file with Nano.gedit [FILE]for opening a file with Gedit (similar to Notepad++).
Before going into more details on them, is important to understand the meaning of each letter in ugo:
user owner: The user who owns a directory or file.group members: Users in the directory or file group.other users: Other users not in the directory or file group.
Beyond those three letters, there is the letter a, which stands for all users. It is the equivalent of ugo, executed altogether. For example, chmod ugo+rwx foo.txt is the same as chmod a+rwx.
We also need to know that rxw stands for:
read if permitted.-if it is not.write if permitted.-if it is not.- e
xecute if permitted.-if it is not. If applied in directories, it means that it can be opened.
Commands:
chownfor changing the owner of file system files or directories. Stands for change owner. It is important to note that normal users can change the group of the file only if they own the file and only to a group of which they are a member. Administrative users can change the group ownership of all files.chown [USER NAME|UID] [FILE] …for changing the ownership of a file/directory to a new owner. It accepts multiple arguments for changing the ownership of multiple files/directories at once. E.g.chown jc foo.txt bar.txtandchown 1000 /pictures. UID stands for User Id, which can be displayed by the commandid.chown :[GROUP|GID] [FILE] …for changing the ownership of a file/directory to a new group. GID stands for Group Id.chown [USER|UID]:[GROUP|GID] [FILE] …for changing the ownership of a file/directory to a new user and group.chown [-h|--no-dereference] [USER|UID]:[GROUP|GID] [SYMLINK]for changing the ownership of the symlink itself.chown --reference=[FILE OF REFERENCE] [FILE] …for changing the user and group ownership of given files to be same as those of the [FILE OF REFERENCE]. E.g.chown --reference=/pictures/foo.txt bar.txt.- Remember to add the
[-R|--recursive]flag for apply the commands above to directories, such as this:chown -R jc:group1 /downloads.
-
chmodfor changing the access permissions of file system objects (a.k.a. modes). Given permissions are in octal. Stands for change mode.Common permissions:
+[r|w|x]: Same aschmod ugo+[r|w|x] [FILE]. Grants the specfied permission(s). E.g.chmod +x foo.txt,chmod ugo+rx foo.txt,chmod u+r foo.txt.=[r|w|x]: Same aschmod ugo=[r|w|x] [FILE]. Causes the permission(s) to be added and causes unmentioned bits (permissions) to be removed except that a directory's unmentioned set user and group ID bits are not affected. E.g:$ touch foo.txt ; ls -l foo.txt -rw-r--r-- 1 jc jc 0 Jul 12 05:23 foo.txt* $ chmod u+x foo.txt; ls -l foo.txt -rwxr--r-- 1 jc jc 0 Jul 12 05:23 foo.txt* $ chmod u=x foo.txt; ls -l foo.txt ---r--r-- 1 jc jc 0 Jul 12 05:23 foo.txt*-[r|w|x]: Same aschmod ugo-[r|w|x] [FILE]. Revokes the specified permission(s). E.g.chmod -r foo.txt,chmod ug-x foo.txt,chmod uo-rw foo.txt.- As one can expect, we can combine operations in the same command like this:
chmod u=rw,g-r,o+x foo.txt.
A few octal notation permissions:
777:rwxfor everyone. Same aschmod ugo=rwxE.g.chmod 777 [FILE]chmod 777 -R [DIRECTORY]. Symbolic notation:-rwxrwxrwx770:rwxpermissions foruser owner andgroup. Same aschmod ug=rwx [FILE].755:rwxpermissions for theuser owner andrxpermission for thegroup members andothers. Same aschmod u=rwx,go=rx [FILE].700:rwxforuser owner. Same aschmod u=rwx [FILE]. Symbolic notation:-rwx------.
These are a few examples but, how can we form our own octal notation permission? Well, it is as simple as this:
If we wanted to know the octal notation of u=rx,g=x,o=rw then we know that the user owner permissions are translated into 5, then the group permission into 1 and, finally, the others permissions into 6.
Another mnemotecnichal rule for remembering this is to associate that r=4, w=2 and x=1. However, it is necessary to understand from where these numbers come from:
ris 4 in decimal because it is on the third bit from the right (r--). It's 1*2²=4.wis 2 in decimal because it is on the second bit from the right (-w-). It's 1*2¹=2.xis 1 in decimal because it is on the first bit from the right (--x). It's 1*2⁰=1.
cd ..for going up one level of the directory tree. Stands for change directory.cd [DIRECTORY]for opening to a certain directory.cd ~or justcdfor going to the HOME directory.cd -for going to the previous directory.
hostfor performing DNS lookups. It is normally used to convert names to IP addresses and vice versa. When no arguments or options are given, host prints a short summary of its command line arguments and options.ping [DOMAIN|IP]for checking whether a network is available and if a host is reachable.dig [DOMAN|IP]for querying DNS name servers. Stands for Domain Information Groper.ifconfigfor displaying current network configuration information, setting up an ip address, netmask, or broadcast address. Stands for interface configuration.ftpfor connecting to a FTP server.lftpfor connecting to a FTP or SFTP server. It has to be installed viaaptwith the commandsudo apt install lftp.
wget [URL]for retrieving content from the Internet. Stands for World Wide Web Get.wget [-O|--output-document=] [NAME] [URL]for saving the downloaded file under a different name instead of its original name.wget [-P|--directory-prefix=] [DIRECTORY] [URL]for saving the file to a specific location. Bear in mind that, by default,wgetwill download the file in the current working directory.wget --limit-rate=[RATE][k|m|g] [URL]for limiting the download speed to the specified [RATE]. The rate can be inkilobytes,megabytes andgigabytes. Example:wget --limit-rate=5m https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz.wget [-c|--continue] [URL]for resuming a download. Notice that, if the remote server does not support resuming downloads,wgetwill start the download from the beginning and overwrite the existing file.wget [-b|--background] [URL]for downloading the file in the background.wget [-U|--user-agent=] "[USER AGENT]" [URL]for emulating a different browser, in case that the remote server block the Wget User-Agent. E.g.wget --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" http://wget-forbidden.com/.wget [-i|--input-file] [-|FILE]for downloading multiple files at once from a file (if we enter the name of a file) or from the standard input (if we enter a dash).wget [-m|--mirror] [URL]for creating a complete local copy of a website by following and downloading all internal links as well as the website resources (HTML, JavaScript, CSS and images).wget [-mkp|-m -k -p] [URL]for downloading a website for local browsing. The-kflag will causewgetto convert the links in the downloaded documents to make them suitable for local viewing. The-pflag will tellwgetto download all necessary files for displaying the HTML page.wget --no-check-certificate [URL]for downloading a file over HTTPS from a host that has an invalid SSL certificate.
