How to Use Shell Command to tar Directory Excluding Files/Folders?
Linux shell command “tar” supports the “–exclude” argument to exclude certain files/directories by placing them one after the other.
Linux shell command “tar” supports the “–exclude” argument to exclude certain files/directories by placing them one after the other.
To create a link to a directory, use the “ln(link)” command followed by the “-s” flag at the current working directory or the user-choice location.
In a Bash script, the “set -e” identifies the error location and exits the script execution quickly without the execution of other commands.
To extract file basename without path and extension, use the “basename” command. It can be done using the “parameter expansion” without the “basename.”
The string variables can be easily concatenated by “placing them sequentially” and using the “+=” operator in Bash shell scripts.
To change the dictionary in the current bash shell execute the script(bash) having the cd command with the “dot(.)” symbol and the “source” command.
Bash provides the “-v”, “-z”, and “-n” options to check whether the variable is set or not, at the conditional statement of the “if-then-else-fi” loop.
To compare two files in a Linux terminal, use the “diff(difference)” command, its supported “–color” flag for colorized output, and the “vimdiff” command.
The “-f(follow)” parameter of the “tail” command is mainly used by the system administrator for monitoring the text and log files in real-time.
In Linux, the “grep” command allows the “-l(files-with-matches)” flag and the combination of the “find” command to show just filenames.
The “Ctrl-Z” key and the “&(ampersand)” symbol are different on the basis of their “objectives”, “usage”, “implementation” and “states”.
Bash nested “for” loop contains the inner for loops that iterate entirely for each value of the outer for loop and execute the block of statements.
Linux bash scripting uses the “set -x” and “set -v” commands to echo the defined set of shell commands placed in it at any point.
To stop the Docker under Linux, utilize the “systemctl” and “service” command line manager with the “stop” utility. Follow the detailed procedure here
To restart the “PostgreSQL” server in Ubuntu, use the “systemctl” and “service” command line managers with the “sudo” support in case of non-root users.
To create desktop shortcuts, copy an application’s “.desktop” file to the “~/Desktop.” Use the “ln” command in the terminal for the desktop file shortcut.
To customize GNOME in Ubuntu, install the “Extension Manager” tool that provides many free and open-source extensions. Read this post for more details.
The “ClamAV” CLI is installed from the Ubuntu standard repository via the “apt” and “ClamTK” GUI interface from the “Ubuntu Software” center.
The “bg” places the foreground job in the background, and the “fg” resumes the background jobs. However, the “Ctrl+Z” key keeps the job in a “stopped” state.
In Linux, the bash shell variable “$$” returns the current bash shell process id that can be checked through the “echo” and the “ps(process)” commands.
To comment out multiple lines at once using the “vim” text editor “line number,” “regular expression,” and the “Visual Mode” feature properly.
The vim editor performs the change, replace, and substitute operation using the “Slash(\) and Dot(.)” operator, the “Substitute Command,” and “Line Number.”
To put a new line into a file using the echo command and redirection operator, use the “e” flag and separate each string by the special character “\n.”
The “ncdu” provides a command line interface to check the disk space details at the window’s bottom. For more details, follow this post.
To check the “install” package version, use the “apt-get” command with the “-s(simulation)” flag and the “aptitude” with the “version” flag.
The “Bash Indexed” array is a sequential arrangement of different types of elements associated with an “index,” a non-negative integer value.
To print all values of the array used in the sh script, utilize the “@” or “*” symbol at the indexed position. This task can also be done with the “for” loop.
To find the specific device drivers, use the “modinfo” command with the particular device name. For only the USB driver details, use the “lsusb” command.
In Ubuntu and other Linux distributions, the “virt-manager” can be installed simply from the local repository using default package managers.
The “split()” is the “awk” command line function that splits the defined string into an “awk” array separated by the delimiter(default/user-choice).
The “not equal” operator is the relational operator used to compare the two strings or the specified string. For more details, read this guide.
Ubuntu operating system supports a large list of command line text editors from which, most commonly, “nano” and “vim” are used to edit files.
In Linux, the sed Command: sed ‘s/\s\s*/ /g’ allows the users to replace more than one whitespace character or tab with a single whitespace globally.
The “$PWD” is an environment variable that contains the absolute path of the current working directory starting from the “root(\)” directory.
To convert the argument string to an integer using the “$((…))” arithmetic expansion operator, “expr,” “let,” “bc,” and “awk” commands in the bash script.
In Linux, the bash addition and multiplication operations can be performed using the “arithmetic expansion,” “expr,” and the “let” command line utility.
The “bash” and “sh” shells are different based on their “functionality,” “POSIX shell,” “programming language,” “compatibility,” and “command history.”
The “find” is the built-in command for finding files/directories based on their name, username, group, … Read More
Ubuntu supports “Evince”, “Zathura”, and “Atril”, PDF document viewers. These PDF viewers have simple interfaces alongside their unique functionalities.
To set the manual date and time of the system, use the “date”, “timedatectl”, “hwclock”, and “ntpdate” commands and the “Date &Time” option via GUI.
The “LD_LIBRARY_PATH” environment variable searches the directories of the shared libraries. It can also be set in Linux using the “export” command.
The sshd Logs are stored in the “/var/log/auth.log” file. These log details can be displayed using the “grep”, “lastlog”, and the “journalctl” commands.
To replace a “\n(newline)” to a “,(comma)” use the “sed” command “-z”, “H, h, d, x and y”, “-n, H, h, g, and p ”, “H, x, p”, and “a, b, $! and N” flags.
In Linux and its distributions, the user can easily create the home directory for an existing user with the help of the “mkdirhome_helper” command.
In Linux, the “sort” command line utility is used with the “-k” flag to perform the sorting operation based on the third column.
In Linux, use the “date”, “$SECONDS” internal bash variable, and the “TIMEFORMAT” string to get the execution time of the bash script.
In Linux, the “daemon-reload” reloads the entire systemd unit files while the “reload” only reloads the specific service configuration files.
In Ubuntu, the alternatives to Notepad++ are “Nano”, “Gedit”, “Vim”, “Sublime text”, “Geany”, and “Kate”. Read this post for their detailed description.
The “/var/lib/apt/lists” directory stores all the package information downloaded from the ubuntu server when the user runs the “sudo apt command”.
To trim the leading and trailing whitespaces from each line in the output of a file/script, use the Linux pre-installed “sed” and “awk” command line tools.
To sort the output of the “ls” command by modification date use its “-t” argument, and also the “-l(list)” flag that displays the “date&time” of the file/directory.
In Linux, the pre-installed “xrandr” command offers the “newmode” and the “addmode” flags to set the custom resolution of the system monitor.
To count the total number of occurrences of the specified word/pattern, use the “grep” command with the “wc(word count)” and “tr(translates)” options.
To convert epoch timestamp to human-readable format use the “date” command, “awk” having starftime format, and the “localtime()” with the “echo” command.
To color diff output use the “diff –color” command for the newer version of “diff” and the “colordiff” command line tool for the older versions.
To reinstall the “pip3” for Python3 and “pip” for Python 2 use the default “apt” package manager with superuser privileges or log in as a root user.
In Ubuntu, the “clean”, “autoclean”, and “autoremove” commands clean up the system cache, additional dependencies, and outdated versions of packages.
To add new lines, use the “-e(backspace interpreter)” and “$(bash variable)” with the “echo” command. An “echo” tool can also be used multiple times to do this.
In Linux and its distributions, the “curl” can be installed via default package managers i.e “apt” (Ubuntu/Debian), “yum” (CentOS/RHEL), and “dnf” (Fedora).
To generate a strong password, use the “urandom”, “makepasswd”, “gpg”, “apg”, “pwgen”, and “openssl rand” commands. It can also be done using the “Perl” script.
To update the NodeJs versions in Ubuntu, use the “NVM(Node Version Manager)”, “NPM(Node Package Manager)”, and “Binary Packages”.
In Linux, SUID, SGID, and Sticky bit are permission bits that are utilized to specify special permission rules for the file or directory.
The “cd -” and “cd ~-” jump into the recently used directory but the “cd -” also prints that directory’s absolute path in the terminal.
Use the “for” and “while” loops in the shell script to read the file content line by line. Both these loops provide simple syntax to perform this task easily.
To run a shell script in the background, use the “&(ampersand)” bash control operator and the built-in “nohup” command line tool.
To create a permanent bash alias, edit the “~/.bashrc” file in Linux. After that, reload it using the “source ~/.bashrc” command to activate newly alias.
In bash scripting, the “if” loop is used to execute multiple conditional statements using “if-then fi”, and “if then else fi” and “if then else if fi” loop.
The “exit 0”, “exit 1”, and the “exit 2” returns the exit status of the bash shell script. The value of the exit command is stored in the “$(shell)” variable.
In Bash, the “declare” command sets the variable and functions alongside their attributes, “integer”, “string”, “array”, and “read-only” variables.
Linux offers the “systemctl” and “service” commands to restart the “SSH” service instantly. It can also be restarted by accessing the “/etc/init.d” directory.