How to Delete Files and Directories in the Linux Terminal

Type “rm (filename)” in the Terminal to remove a file on Linux. To remove an entire folder (or directory) and all of its contents, type “rm -r (foldername)” into the Terminal instead.

The rm and  rmdir commands delete files and directories on Linux, macOS, and other Unix-like operating systems. They’re similar to the del and  deltree commands in Windows and DOS. These commands are very powerful and have quite a few options. It is important to note that files and directories deleted using rm and rmdir do not get moved to the Trash. They are immediately removed from your computer. If you accidentally delete files using these commands, the only way you’ll be able to restore them is from a backup.

[mai mult...]

How to Use the wc Command in Linux

The wc command is a small application. It’s one of the core Linux utilities, so there is no need to install it. It’ll already be on your Linux computer. You can describe what it does in a very few words. It counts the lines, words, and bytes in a file or selection of files and prints the result in a terminal window. It can also take its input from the STDIN stream, meaning the text you want it to process can be piped into it. This is where wc really starts to add value.

It is a great example of the Linux mantra of “do one thing and do it well.” Because it accepts piped input, it can be used in multi-command incantations. As we’ll see, this little standalone utility is actually a great team player.

One way I use wc is as a placeholder in a complicated command or alias I’m cooking up. If the finished command has the potential to be destructive and delete files, I often use wc as a stand-in for the real, dangerous command. That way, during the development of the command I get visual feedback that each file is being processed as I expected. There’s no chance of anything bad happening while I’m wrestling with the syntax.

As simple as wc is, there are still a few small quirks that you need to know about.

[mai mult...]

How to Find the PID of a Linux Process With pidof or pgrep

To find the process ID of a Linux process, use the pidof command, like this: “pidof examplename”. If you only know part of the PID name, you can use “pgrep examplenamefragment” instead. Replace “examplename” and “examplenamefragment” with the terms you want to search for.

Working with a Linux process often means knowing its process ID, or PID. It’s a unique number given to each piece of running software.

[mai mult...]

How to List Linux Services With systemctl

Services and daemons are background tasks that run without a user interface, don’t require human interaction, and are usually started as the computer boots up.

At one time, services were launched by init, which was the very first process to be launched. The details of the services were held in a collection of scripts located in the “/etc/init/d” directory. On non-systemd distributions that’s still the case.

In the systemd world, services are launched by systemd which is the now first process to be launched. The details of the services are stored in unit files located in the “/usr/lib/systemd” directory.

According to its man page, systemd is a system and service manager. You can use the systemctl command to inspect and control different aspects of the systemd system, including services and daemons.

Because we’re looking at systemd-specific commands here, the first thing you need to know is whether you’re running a systemd-based distribution or not.

[mai mult...]

9 Useful Examples of the Linux rsync Command

  • The rsync Tool

The rsync tool copies files and directories between two computers. It uses a sophisticated algorithm that scans directory trees to find files on the source computer that don’t exist on the destination computer. These files are transmitted to the destination computer. What makes rync so clever is it can figure out which pieces of existing files have been modified, and it only sends the changed portions.

You can use rsync to copy files to a different location on your hard drive, to a different hard drive in the same computer, to an externally connected USB drive, or any other network-accessible location.

On top of that, rsync can optionally preserve symbolic links, hard links, and file metadata such as file ownership, permissions, and access times. To support all this functionality, rsync has many options and figuring them all out takes time. We’ve collected these 10 examples to help you get started. We’ve already written about doing backups with rsync , so we’re concentrating on other uses here.

For all of its many options, the structure of an rsync command is simple. We need to provide the source, the destination, and the options we want to use. You’ll probably find that rsync is already installed on your Linux computer—it was, on all of our test machines—but if it isn’t it’ll definitely be in your distribution’s repositories.

[mai mult...]