Technology / System Admin

20 Linux Commands You Need for the A+ (and Beyond)

20 Linux Commands You Need for the A+ (and Beyond) picture: A
Follow us
Published on October 21, 2020

CompTIA's A+ certification is one of the top entry-level certifications in the IT industry. It covers a wide range of topics without going too deep. This makes it useful for IT pros looking for a solid foundation to help launch their career.

Because it's an entry-level cert, it may also be the first time some cert-seekers have to understand basic Linux commands. The command line in general can be intimidating, and when you add in a new operating system, it can sound even worse.

Fortunately, there's nothing too difficult about the Linux commands listed in the A+ objectives. A little studying and practice will get you familiar with these commands in no time.

Basic Linux A+ Command List

Objective 1.9 of the CompTIA A+ Core 2 (200-1002) exam calls out 20 different Linux/Mac OS commands.  Those *nix commands are:

  1. ls

  2. grep

  3. cd

  4. shutdown

  5. pwd

  6. passwd

  7. mv

  8. cp

  9. rm

  10. chmod

  11. chown

  12. iwconfig

  13. ifconfig

  14. ps

  15. su

  16. sudo

  17. apt-get

  18. vi

  19. dd

  20. kill

That gives us a specific set of commands to focus our efforts on. Before we jump into examples, let's cover some basic information on switches and man pages.

Understanding Linux Commands: switches/options

You'll notice that some of our command examples include a dash "-" followed by some characters, like ls -l. The dash plus additional characters are commonly referred to as "switches" or "options". These switches are optional (i.e. you can use the command without them). Generally, a switch will modify what a command does in some way.

For example, simply adding the -l switch to ls tells us a whole lot more about file permissions.  Often, you can combine switches to apply multiple options at once.

Understanding the concept of switches is an important part of mastering Linux commands.

Understanding Linux: man/info & help

There are tons of different options and ways to use even basic Linux commands. Here, we'll focus on common usage and avoid getting too far into the weeds. However, it's important to know you can get detailed information on command usage straight from a Linux terminal. Generally, this will involve typing man  (e.g. man ls), info , or command –help. You can also find man pages online, for example this fairly long list on man7.org.

Don't worry about mastering all the different usage scenarios now. Just know that there is a place to look if you ever get stuck working with a command.

Linux Commands: Prompts, Home Directories, Examples

When you are looking at a Linux terminal, you'll see a prompt that usually ends with a dollar sign $ (for normal users) or a pound sign # (for the superuser or root user). Often that prompt is in the form of username@computername:<current working directory> (~ means the user's home directory) You'll get used to this fast, but for beginners it's important to note that the commands are everything after the prompt.

For example, in this article, we're using a user named "cooluser" on an Ubuntu install. Therefore, preceding most of our commands you'll see this:

:~$

Remember: There is no need to type anything before the $ if you're practicing with the examples here.

Your prompt will look a little different, usually with a username behind it. The prompts you see in other online examples may differ as well. Some may have different prompts. Some may exclude the prompt altogether. Others may just use the $ or # to indicate if commands are run as a normal user or a superuser/root user.

Avoiding Typos: Tab Completion is Your Friend

When you're working in a command line, it's easy to make typos. On most modern Linux systems, tab completion can help minimize typing errors. The way tab completion works is simple: hitting the TAB key will complete as much of the command as possible for you given what you have typed. This is particularly useful when dealing with different paths on a system.

For example, if we were going to change directory (using cd) from /home/cooluser/ to /home/cooluser/subdirectoryone and there was no other file or directory starting with an "s" in /home/cooluser/, simply typing cd s and pressing the TAB key will autocomplete to cd subdirectoryone.

20 Linux Commands: Explanations and Examples

With those prerequisites and tips out of the way, let's dive into the list of Linux commands for the A+ exam. For each command, we'll provide an explanation and examples to help you get started.

We've combined a few of the entries, specifically "pwd vs password", "iwconfig/ifconfig", and "su/sudo", to be consistent with how they are listed on the A+ exam objectives.

Command 1: ls

ls is a very common Linux command. It is used to list files and directories within a directory. When used with different switches, ls can tell you a lot about files and permissions.

ls by itself prints (displays) all the files and directories in your current working directory:

:~$ ls
accouting.csv  coolpictures.png  interestingscript.sh  learningnotes.txt  logessay.docx
:~$

ls /path/to/another/directory/ lists all the files and directories in /path/to/another/directory/ (fill in the path to make sense for your system). You can use this same /path/to/another/directory/ approach with other switches and other commands as well. In this example, we list the files in /tmp/tempfiles/:

:~$ ls /tmp/tempfiles/
draftscript.sh  interestingstory.tmp  knowledge.nugggets
:~$

ls -l lists files and directories as well as their permissions, user that owns the file/directory, group that owns the file/directory last modified date/time, and the total file system blocks used.

:~$ ls -l
total 0
-rw-rw-rw- 1 cooluser cooluser   0 Jun 24 21:50 accouting.csv
-rw-rw-rw- 1 cooluser cooluser   0 Jun 24 21:50 coolpictures.png
-rw-rw-rw- 1 cooluser cooluser   0 Jun 24 21:50 interestingscript.sh
-rw-rw-rw- 1 cooluser cooluser 168 Jul  3 13:31 learningnotes.txt
-rw-rw-rw- 1 cooluser cooluser   0 Jun 24 21:50 logessay.docx
:~$

ls -a includes hidden files, those that start with a ".", in the ls output.

:~$ ls -a
.bash_logout  .config     .motd_shown  .sudo_as_admin_successful  coolpictures.png      logessay.docx
.bashrc       .landscape  .profile     .viminfo                   interestingscript.sh
.bash_history  .cache        .local      .ssh         accouting.csv              learningnotes.txt

Command 2: grep

grep looks for specific patterns in text files or other input such as the output of a command. Specifically, grep looks for and displays the lines that match a given regular expression a.k.a. regex.

For example, to find the word "sysadmin" in the plaintext file "learningnotes.txt" we can use grep "sysadmin" learningnotes.txt

:~$ grep “sysadmin” learningnotes.txt
sysadmin
sysadmin's work hard
sysadmins study a lot
sysadmins are admins of systems
:~$

If we wanted to narrow that down to times we typo'd sysadmins with an apostrophe, we can use grep “sysadmin’s” learningnotes.txt

:~$ grep “sysadmin’s” learningnotes.txt
sysadmin’s work hard
:~$

To do a case insensitive search, we can use the -i switch, like this: grep -i “sysadmin” learningnotes.txt (notice in this check, we also found "SysADmIn").

:~$ grep -i “sysadmin” learningnotes.txt
sysadmin
sysadmin’s work hard
sysadmins study a lot
sysadmins are admins of systems
SysADmINn
:~$

It's also very common to use grep to parse the output (stdout) of a command. To do that, we simply type the command, a pipe "|", and then the grep command we want to apply. For example, ls | grep “.txt” will print only files with .txt in their name in the current working directory.

:~$ ls | grep “.txt”
learningnotes.txt
:~$

Pro-tip: In practice, a command like find is often better than using grep and ls together.

Command 3: cd

cd is used to "change directories". If you need to navigate to different directories, cd is likely the tool you'll want. When working with cd, it is important to understand absolute paths vs relative paths. Absolute paths start with a leading /. Relative paths do not start with a leading /. The leading / is the root directory on your system. With relative paths, cd starts from your current working directory.

Let's use an example to get a feel for cd and paths. In our example, our home directory is /home/cooluser. In that directory, there is one subdirectory, /home/cooluser/subdirectoryone. In /home/cooluser/subdirectoryone there is one more subdirectory, /home/cooluser/subdirectoryone/subdirectorytwo.

Let's start at /home/cooluser. From here, we can cd subdirectoryone to enter subdirectoryone (pwd as we'll see in a subsequent section prints the current working directory).

:~$ pwd
/home/cooluser
:~$ cd subdirectoryone/
:~/subdirectoryone$ pwd
/home/cooluser/subdirectoryone
:~/subdirectoryone$

From here, we can cd subdirectorytwo to move to the next subdirectory.

:~/subdirectoryone$ cd subdirectorytwo/
:~/subdirectoryone/subdirectorytwo$ pwd
/home/cooluser/subdirectoryone/subdirectorytwo
:~/subdirectoryone/subdirectorytwo$

Now that we're in /home/cooluser/subdirectoryone/subdirectorytwo, let's try to get back to subdirectoryone with cd subdirectoryone

:~/subdirectoryone/subdirectorytwo$ cd subdirectoryone
-bash: cd: subdirectoryone: No such file or directory
:~/subdirectoryone/subdirectorytwo$

Interestingly, we get a "cd: subdirectoryone: No such file or directory" error. But we know subdirectoryone exists. We also know cd subdirectoryone got us to /home/cooluser/subdirectoryone just a few minutes ago. So, what's the difference now?

In our first attempt, subdirectoryone was within our current working directory. That is, it was available to cd to relative to where we were at (/home/cooluser). Once we were in /home/cooluser/subdirectoryone/subdirectorytwo, there is no subdirectoryone relative to our current working directory, so the cd command fails.

We can address this problem by using cd with the absolute path of /home/cooluser/subdirectoryone, like this cd /home/cooluser/subdirectoryone.


Alternatively, we can use cd ..  to move "up" one directory, like this:

:~/subdirectoryone/subdirectorytwo$ pwd
/home/cooluser/subdirectoryone/subdirectorytwo
:~/subdirectoryone/subdirectorytwo$ cd ..
:~/subdirectoryone$ pwd
/home/cooluser/subdirectoryone
:~/subdirectoryone$

To move to the "root" directory of a system, use cd /

:~$ pwd
/home/cooluser
:~$ cd /
:/$ pwd
/
:/$

Command 4: shutdown

shutdown as you may expect, powers off, halts, or reboots the system depending on the switches you use. The general usage for shutdown is shutdown [options] [time] [wall]. "Wall" is a message to be displayed to users when the shutdown begins.

shutdown by itself is used to power down the system (usually with a default one-minute delay).

:~$ shutdown

shutdown -H does a halt instead of a power down.

:~$ shutdown -H

shutdown -r kicks off a reboot

:~$ shutdown -r

shutdown now or shutdown +0 shuts down the system immediately. Without the one-minute delay.

:~$ shutdown now
:~$ shutdown +0

shutdown -r +5 begins a reboot of the system in five minutes.

:~$ shutdown -r +5

shutdown -c cancels a pending shutdown command.

:~$ shutdown -c

Command 5 & 6: pwd vs. passwd

Sometimes, password is abbreviated as pwd. Therefore, you may expect that the pwd and passwd commands do something similar, but they don't. pwd displays the present working directory. passwd is used for changing passwords.

For example, if we go back to our previous directory examples, when we are in /home/cooluser, pwd will print that to the screen.

:~$ pwd
/home/cooluser
:~$

The passwd command on the other hand will bring us the prompt to change our own password.

:~$ passwd
Changing password for cooluser.
Current password:
New password:
Retype new password:
passwd: password updated successfully
:~$

If we wanted to change a password for another user named "seconduser" we need sudo privileges, which we have (more on sudo below), and then we just enter sudo passwd seconduser and follow the prompts.

:~$ sudo passwd seconduser
[sudo] password for cooluser:
New password:
Retype new password:
passwd: password updated successfully
:~$

Command 7: mv

The mv command is used to move (not copy) files from one place to another. Because of how it works, mv is also useful for renaming files. mv has a variety of options related to backups and overwriting or not overwriting files, but basic usage is as simple as.

:~$ mv

In the example below, we have a "coolpictures.png" file in our current working directory we want to rename to "awesomepics.png". We can do that with the command mv coolpictures.png awesomepics.png.

:~$ ls
accouting.csv  coolpictures.png  interestingscript.sh  learningnotes.txt  logessay.docx  subdirectoryone
:~$ mv coolpictures.png awesomepics.png
:~$ ls
accouting.csv  awesomepics.png  interestingscript.sh  learningnotes.txt  logessay.docx  subdirectoryone
:~$

You can use mv with absolute or relative paths. To move our "accounting.csv" file to /tempdir we can use the command mv accounting.csv /tmpdir.

:~$ ls
accounting.csv  awesomepics.png  interestingscript.sh  learningnotes.txt  logessay.docx  subdirectoryone
:~$ mv accounting.csv /tmpdir
:~$ ls /tmpdir/
accounting.csv
:~$ ls
awesomepics.png  interestingscript.sh  learningnotes.txt  logessay.docx  subdirectoryone
:~$

Similarly, to move our "longessay.docx" file to /home/cooluser/subdirectoryone and rename it "greatessay.docx" while in /home/cooluser, we can use mv longessay.docx subdirectoryone/greatessay.docx.

:~$ ls
awesomepics.png  interestingscript.sh  learningnotes.txt  longessay.docx  subdirectoryone
:~$ mv logessay.docx subdirectoryone/greatessay.docx
mv: cannot stat ‘logessay.docx’: No such file or directory
:~$ ls
awesomepics.png  interestingscript.sh  learningnotes.txt  longessay.docx  subdirectoryone
:~$ mv longessay.docx subdirectoryone/greatessay.docx
:~$ ls subdirectoryone/
greatessay.docx  subdirectorytwo
:~$ ls
awesomepics.png  interestingscript.sh  learningnotes.txt  subdirectoryone
:~$

To move all the files in a directory, you can use an asterisk * can be used as shorthand for "everything here". For example, to move the contents of our current working directory to /tmpdir we can use the command mv * /tmpdir.

:~$ ls /tmpdir/
accounting.csv
:~$ ls
awesomepics.png  interestingscript.sh  learningnotes.txt  subdirectoryone
:~$ mv * /tmpdir/
:~$ ls /tmpdir/
accounting.csv  awesomepics.png  interestingscript.sh  learningnotes.txt  subdirectoryone
:~$ ls
:~$

Command 8: cp

Once you understand mv, it's easy to understand cp. They work similarly, but cp copies instead of moves files. Going back to our original mv coolpictures.png awesomepics.png. example, we can use cp coolpictures.png awesomepics.png to make a copy of "coolpictures.png" named "awesomepics.png" without getting rid of the original.

:~$ ls
coolpictures.png  interestingscript.sh  learningnotes.txt  longessay.docx  subdirectoryone
:~$ cp coolpictures.png awesomepics.png
:~$ ls
awesomepics.png  coolpictures.png  interestingscript.sh  learningnotes.txt  longessay.docx  subdirectoryone
:~$

Command 9: rm

rm is used to delete or "remove" files. Use caution when working with rm, as you won't always have the benefit of something like a recycle bin on Linux systems.

To remove the file "junkfile.txt" that is in our current working directory, we can use the command rm junkfile.txt

:~$ ls
awesomepics.png  coolpictures.png  interestingscript.sh  junkfile.txt  learningnotes.txt  longessay.docx  subdirectoryone
:~$ rm junkfile.txt
:~$ ls
awesomepics.png  coolpictures.png  interestingscript.sh  learningnotes.txt  longessay.docx  subdirectoryone
:~$

If the file was in a different directory, we could use absolute and/or relative paths to delete it. Like many other commands, rm can be used with the asterisk wildcard character.

If you need to delete a directory with files in it, rm without any switches won't cut it. You can (with caution!), use rm -r though. For example, from /home/cooluser/subdirectoryone we can use rm -r subdirectorytwo to delete /home/cooluser/subdirectoryone/subdirectorytwo and its contents.

:~/subdirectoryone/subdirectorytwo$ cd ..
:~/subdirectoryone$ ls
subdirectorytwo
:~/subdirectoryone$ rm -r subdirectorytwo/
:~/subdirectoryone$ ls
:~/subdirectoryone$

Command 10: chmod

Linux file permissions can get a bit complex, which is why we wrote a piece that focuses on chmod and chown[a]. For now, let's focus on the basics of these two commands. Here we'll look at chmod, which is used to modify the read, write, and execute permissions on a file. For example, suppose we wanted to add "execute" permissions for all users to our "interestingscript.sh" file.

We can use the command sudo chmod +x interestingscript.sh to do that. As you can see in the example below, the "x" (for execute) permission was added for the user that owns the file (the "x" that is the fourth character in the ls -l interestingscript.sh output), group that owns the file (seventh character), and everyone else (tenth character).

:~$ ls -l interestingscript.sh
-rw-rw-rw- 1 cooluser cooluser 0 Jul  3 15:10 interestingscript.sh
:~$ sudo chmod +x interestingscript.sh
[sudo] password for cooluser:
:~$ ls -l interestingscript.sh
-rwxrwxrwx 1 cooluser cooluser 0 Jul  3 15:10 interestingscript.sh
:~$

Command 11: chown

chown is how you configure who owns a file. Sticking with our "interestingscript.sh" example, suppose we wanted to change the user that owns the file to "seconduser" and the group to seconduser's group. For that, we can use the command sudo chown seconduser: interestingscript.sh.

:~$ ls -l interestingscript.sh
-rwxrwxrwx 1 cooluser cooluser 0 Jul  3 15:10 interestingscript.sh
:~$ sudo chown seconduser: interestingscript.sh
:~$ ls -l interestingscript.sh
-rwxrwxrwx 1 seconduser seconduser 0 Jul  3 15:10 interestingscript.sh
:~$

If we wanted to just change the user that owns the file, but not the group, we could have omitted the colon :. i.e. use the command sudo chown seconduser interestingscript.sh.

Command 12 & 13: iwconfig vs ifconfig

Before we dive in here, it's worth noting that the ip command is becoming more and more common on modern Linux systems. In production environments, you may want to get used to using ip instead of ifconfig. In fact, on many modern Linux distributions, you may need to manually install iwconfig and ifconfig.

That said, let's focus on the two called out by the A+ exam objectives for now, iwconfig and ifconfig. Both of these commands  are used to configure and obtain information on network interfaces. The key difference is that iwconfig focuses specifically on wireless interfaces while ifconfig is a general utility. There is plenty you can do with iwconfig and ifconfig, but we'll focus on the basics here.

To display network interface information such as IP address, broadcast address, and subnet mask for all active interfaces, simply enter the ifconfig command with no switches.

:~$ ifconfig

Similarly, to display wireless specific information, like signal level, managed frequency, and access point MAC addresses, simply enter the iwconfig command

:~$ iwconfig

To display information on ALL interfaces (active or inactive) use ifconfig -a

:~$ ifconfig -a

Command 14: ps

ps command is used to get information on process status for running processes. This command can get a bit confusing because there are two approaches to options. The BSD (Berkeley Software Distribution) style options do not use a dash. On the other hand, Linux/Unix/GNU style options that do use dashes. To keep things consistent, we'll focus on the *nix style here.

ps by itself displays all the running processes for the current shell. Here, we can see the PID (Process ID), associated terminal (TTY), amount of CPU time used (TIME), and specific command (CMD) associated with each process.

:~$ ps
   PID TTY      TIME CMD
     4 tty1     00:00:00 bash
   72 tty1     00:00:00 ps

ps -e and ps –A give similar output to ps but includes all active processes.

:~$ ps -e
   PID TTY    TIME CMD
    1 ?          00:00:00 init
    3 tty1     00:00:00 init
    4 tty1     00:00:00 bash
   73 tty1    00:00:00 ps
:~$ ps -A
  PID TTY     TIME CMD
    1 ?          00:00:00 init
    3 tty1     00:00:00 init
    4 tty1     00:00:00 bash
   74 tty1    00:00:00 ps
:~$

Adding the -F switch will provide more detail on running processes. Specifically, with ps -F now we see the user ID of the process owner (UID), the process ID (PID), the parent process's PID (PPID), CPU usage (C), set size of memory allocated (SZ), resident set size (RSS) which is the actual memory in use in kilobytes, processor associated with the process (PSR), time the process started (STIME), and the specific name of the command (CMD).

:~$ ps -F
UID        PID  PPID  C    SZ   RSS PSR STIME TTY          TIME CMD
cooluser     4     3  0  4521  3616   0 11:51 tty1     00:00:00 -bash
cooluser    76     4  0  4662  1888   0 12:13 tty1     00:00:00 ps -F
:~$

Like with other commands on the list, you can combine options to further modify the output of ps.

Command 15 & 16: su/sudo

The command su is used to switch to a different user. The command sudo is used to run a command as a specific user, buy default the superuser or root. Generally, to use sudo a user must be granted specific permissions, often in a file at /etc/sudoers. Let's take a look at a few su and sudo examples.

Note: use caution when running commands as a "root" user or superuser. If you don't have a specific reason to do so, try and avoid running commands with elevated privileges.

To run a command as root, we'll use sudo and supply our password when prompted. Here, we'll use the whoami command which simply prints the current user's username to the screen. Remember that the specific command we use is arbitrary and sudo can be used with most other commands.

:~$ sudo whoami
[sudo] password for cooluser:
root
:~$ whoami
cooluser
:~$

To run a command as "seconduser" we can use the command sudo -u seconduser  and enter our password when prompted.

:~$ sudo -u seconduser whoami
[sudo] password for cooluser:
seconduser
:~$

If we actually want to switch the account we are using, that's where su comes in. For example, to switch to our "seconduser" account, we can use the command su seconduser and input the password for the "seconduser" account. To exit running our shell as "seconduser", we simply type exit.

:~$ su seconduser
Password:
$ whoami
seconduser
$ exit
:~$ whoami
cooluser
:~$

Command 17: apt-get

apt-get is a command used for package management on systems like Debian and Ubuntu that use .deb packages. If you want to do things like install, remove, or update packages, apt-get can help.

It's important to remember that apt-get looks for packages in specific repositories. That means in certain situations, you may need to modify the default repositories your system uses or add additional options to your commands. Often, you can find a list of repositories for your system at "/etc/apt/sources.list".

To keep things simple we'll focus on the basic apt-get commands. In many cases, you'll need to run apt-get as the superuser to have it work, so we'll begin our examples with sudo.

To install a package from a default repository, you can use the command sudo apt-get install . For example, to install the Firefox web browser on Ubuntu, we can use sudo apt-get install firefox.

:~$ sudo apt-get install firefox

… and confirm when prompted.

0 upgraded, 55 newly installed, 0 to remove and 0 not upgraded.
Need to get 64.8 MB of archives.
After this operation, 264 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Similarly, to remove (uninstall) a package, we can use sudo apt-get remove . Therefore, to uninstall Firefox, we can use sudo apt-get remove firefox.

:~$ sudo apt-get remove firefox

… and confirm when prompted.

The following packages will be REMOVED:
  firefox
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 203 MB disk space will be freed.
Do you want to continue? [Y/n] y

For upgrades, updates, and cleaning up old packages, these three commands come in handy:

sudo apt-get update fetches available updates
sudo apt-get upgrade installs select updates
sudo apt-get autoremove removes old packages deemed no longer required

Command 18: vi

vi is a text editing program that has been around for a long time. Many will tell you they favor other text editors, like nano or vim, but you'll still find vi in the wild today. Here's a quick crash course on vi.

To open a file in your current working directory for editing, type vi . For example, to edit our "learningnotes.txt" file, we can enter the command vi learningnotes.txt.

:~$ vi learningnotes.txt

That will open the currently blank file in the vi text editor.

Before we begin adding text, we'll press the INSERT key on our keyboard to enter vi's insert mode.

Now that we're in insert mode, we can use our keyboard to type some text.

When we're ready to exit and save the file, first we press the ESC key to exit insert mode. Then we type :wq and press ENTER to save and exit (or write & quit).

That's it, our changes have been saved to "learningnotes.txt". We can use cat learningnotes.txt to print the contents of "learningnotes.txt" to the screen and verify.

:~$ cat learningnotes.txt
These are the things I learned today:
* Thing 1
* Thing 2
* Thing 3
This is the stuff I want to learn next:
* Thing 4
* Thing 5
* How to make a pepper n’ egg sandwich
:~$

Command 19: dd

dd is the data duplicator command and it is used for converting and copying files. Use cases for dd include creating ISO files, creating bootable USB drives, copying master boot records (MBRs), backing up drives, and converting the case of a text file.

Because dd is a powerful tool, generally only the superuser can use it. The basic usage of dd is

dd if=
of= [options]

Let's look at a few examples.

To convert the "learningnotes.txt" in our current working directory file from our vi example to a version named "LEARNINGNOTES.TXT" with all capital letters, we can use sudo dd if=learningnotes.txt of=LEARNINGNOTES.TXT conv=ucase.

:~$ sudo dd if=learningnotes.txt of=LEARNINGNOTES.TXT conv=ucase
0+1 records in
0+1 records out
168 bytes copied, 0.0042432 s, 39.6 kB/s
:~$ cat LEARNINGNOTES.TXT
THESE ARE THE THINGS I LEARNED TODAY:
* THING 1
* THING 2
* THING 3
THIS IS THE STUFF I WANT TO LEARN NEXT:
* THING 4
* THING 5
* HOW TO MAKE A PEPPER N’ EGG SANDWICH
:~$

To convert "LEARNINGNOTES.TXT" to an all lowercase version named "lowercasenotes.txt" we can use sudo dd if=LEARNINGNOTES.TXT of=lowercasenotes.txt conv=lcase

:~$ sudo dd if=LEARNINGNOTES.TXT of=lowercasenotes.txt conv=lcase
0+1 records in
0+1 records out
168 bytes copied, 0.0032191 s, 52.2 kB/s
:~$ cat lowercasenotes.txt
these are the things i learned today:
* thing 1
* thing 2
* thing 3
this is the stuff i want to learn next:
* thing 4
* thing 5
* how to make a pepper n’ egg sandwich
:~$

While these are very basic examples, dd is quite powerful and can be useful for more practical system administration tasks like creating backups or changing the encoding of a file.

Command 20: kill

kill is used to stop a running process. If you're familiar with stopping a process using taskkill or Task Manager in Windows, kill should be easy to understand.

The most basic syntax of kill is:

:~$ kill

To get the PID of a process with commands we've already covered, ps will be helpful. Below, we ran ps -a and noticed a ping running that we want to kill.

:~$ ps -a
  PID TTY          TIME CMD
    4 tty1     00:00:01 bash
11801 tty2     00:00:00 bash
11835 tty1     00:00:00 ping
11836 tty2     00:00:00 ps
:~$

Because the associated PID is 11835, we simply use the command kill 11835 and afterwards, the ping is no longer running.

:~$ kill 11835
:~$ ps -a
  PID TTY          TIME CMD
    4 tty1     00:00:01 bash
11801 tty2     00:00:00 bash
11837 tty2     00:00:00 ps
:~$

Pro tip: If you already know the name of the process you need a PID for, many Linux systems already have the pidof command that can simplify things. Simply use pidof . For example, to get the PID of top, we can use pidof top.

:~$ pidof top
11838
:~$

Final Thoughts: There's Plenty More to Learn

It may seem like the Linux commands on the CompTIA A+ are a lot to learn, but with some practice it can be done. After you get the basics down, there is plenty more to learn about the Linux command line. As you start putting your knowledge to practice, you should start getting a better feel for how everything fits together.

You'll also likely run into cases where you need an option or command you haven't used before. Understanding how to read man pages and use your foundational knowledge will help when that time comes. Remember, this is only the beginning. Keep learning and applying your skills with CBT Nuggets.


Download

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.


Don't miss out!Get great content
delivered to your inbox.

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.

Recommended Articles

Get CBT Nuggets IT training news and resources

I have read and understood the privacy policy and am able to consent to it.

© 2024 CBT Nuggets. All rights reserved.Terms | Privacy Policy | Accessibility | Sitemap | 2850 Crescent Avenue, Eugene, OR 97408 | 541-284-5522