- Sign Up
What Is Linux?
Linux is an operating system’s kernel. You might have heard of UNIX. Well, Linux is a UNIX clone. But it was actually created by Linus Torvalds from Scratch. Linux is free and open-source, that means that you can simply change anything in Linux and redistribute it in your own name! There are several Linux Distributions, commonly called “distros”.
- Ubuntu Linux
- Red Hat Enterprise Linux
- Linux Mint
Linux is Mainly used in servers. About 90% of the internet is powered by Linux servers. This is because Linux is fast, secure, and free! The main problem of using Windows servers are their cost. This is solved by using Linux servers. The OS that runs in about 80% of the smartphones in the world, Android, is also made from the Linux kernel. Most of the viruses in the world run on Windows, but not on Linux!
Linux Shell or “Terminal”
So, basically, a shell is a program that receives commands from the user and gives it to the OS to process, and it shows the output. Linux’s shell is its main part. Its distros come in GUI (graphical user interface), but basically, Linux has a CLI (command line interface). In this tutorial, we are going to cover the basic commands that we use in the shell of Linux.
Learn how to use the find command in this tutorial from our archives.
It goes without saying that every good Linux desktop environment offers the ability to search your file system for files and folders. If your default desktop doesn’t — because this is Linux — you can always install an app to make searching your directory hierarchy a breeze.
But what about the command line? If you happen to frequently work in the command line or you administer GUI-less Linux servers, where do you turn when you need to locate a file? Fortunately, Linux has exactly what you need to locate the files in question, built right into the system.
The command in question is find . To make the understanding of this command even more enticing, once you know it, you can start working it into your Bash scripts. That’s not only convenience, that’s power.
Let’s get up to speed with the find command so you can take control of locating files on your Linux servers and desktops, without the need of a GUI.
How to use the find command
When I first glimpsed Linux, back in 1997, I didn’t quite understand how the find command worked; therefore, it never seemed to function as I expected. It seemed simple; issue the command find FILENAME (where FILENAME is the name of the file) and the command was supposed to locate the file and report back. Little did I know there was more to the command than that. Much more.
If you issue the command man find , you’ll see the syntax of the find command is:
Naturally, if you’re unfamiliar with how man works, you might be confused about or overwhelmed by that syntax. For ease of understanding, let’s simplify that. The most basic syntax of a basic find command would look like this:
Now we’ll see it at work.
Find by name
Let’s break down that basic command to make it as clear as possible. The most simplistic structure of the find command should include a path for the file, an option, and the filename itself. You may be thinking, “If I know the path to the file, I’d already know where to find it!”. Well, the path for the file could be the root of your drive; so / would be a legitimate path. Entering that as your path would take find longer to process — because it has to start from scratch — but if you have no idea where the file is, you can start from there. In the name of efficiency, it is always best to have at least an idea where to start searching.
The next bit of the command is the option. As with most Linux commands, you have a number of available options. However, we are starting from the beginning, so let’s make it easy. Because we are attempting to find a file by name, we’ll use one of two options:
name – case sensitive
iname – case insensitive
Remember, Linux is very particular about case, so if you’re looking for a file named Linux.odt, the following command will return no results.
If, however, you were to alter the command by using the -iname option, the find command would locate your file, regardless of case. So the new command looks like:
Find by type
What if you’re not so concerned with locating a file by name but would rather locate all files of a certain type? Some of the more common file descriptors are:
f – regular file
l – symbolic link
c – character devices
b – block devices
Now, suppose you want to locate all block devices (a file that refers to a device) on your system. With the help of the -type option, we can do that like so:
The above command would result in quite a lot of output (much of it indicating permission denied ), but would include output similar to:
Voilà! Block devices.
We can use the same option to help us look for configuration files. Say, for instance, you want to locate all regular files that end in the .conf extension. This command would look something like:
The above command would traverse the entire directory structure to locate all regular files ending in .conf. If you know most of your configuration files are housed in /etc , you could specify that like so:
The above command would list all of your .conf files from /etc ( Figure 1 ).
Figure 1: Locating all of your configuration files in /etc.
Outputting results to a file
One really handy trick is to output the results of the search into a file. When you know the output might be extensive, or if you want to comb through the results later, this can be incredibly helpful. For this, we’ll use the same example as above and pipe the results into a file called conf_search. This new command would look like:
You will now have a file ( conf_search ) that contains all of the results from the find command issued.
Finding files by size
Now we get to a moment where the find command becomes incredibly helpful. I’ve had instances where desktops or servers have found their drives mysteriously filled. To quickly make space (or help locate the problem), you can use the find command to locate files of a certain size. Say, for instance, you want to go large and locate files that are over 1000MB. The find command can be issued, with the help of the -size option, like so:
You might be surprised at how many files turn up. With the output from the command, you can comb through the directory structure and free up space or troubleshoot to find out what is mysteriously filling up your drive.
You can search with the following size descriptions:
b – 512-byte blocks
We’ve only scratched the surface of the find command, but you now have a fundamental understanding of how to locate files on your Linux systems. Make sure to issue the command man find to get a deeper, more complete, knowledge of how to make this powerful tool work for you.
Learn more about Linux through the free “Introduction to Linux” course from The Linux Foundation and edX.
U nder KDE or Gnome desktop I get nice facility to search all man pages for particular command or phrase. I am login to remote server over the ssh session. How do I search all the man pages for a particular command at Linux shell prompt?
You need to use the following commands to search man pages:
The apropos command searches a set of database files containing short descriptions of system commands for keywords and shows the result on the screen. The syntax is as follows:
apropos Command Examples
To Search command / functions related to compare operation, enter:
$ apropos compare
Task: Search For a String
Search command to remove a file, enter:
$ apropos “remove file”
Task: Search Specific Section of The Man Page
To search only the given manual section use the -s option:
apropos -s 1 compare
Task: Regex Based Search
You can force apropos to interpret each keyword as a regular expression using the -r option:
$ apropos -r scanf
The ‘man -K’ Command
The -K option is passed to the man command to search for the specified string in all man pages. The syntax is as follows:
Search all man pages for fopen word, type:
$ man -K “fopen”
Type y to open/display man page, n to continue search, q to Quit search. This is a brute-force search, and is likely to take some time. So it helps to specify a man page section (1-7) using the following syntax:
$ man -s 3 -K “open”
$ man -s 8 -K “user”
Please note that above commands also works with other UNIX and *BSD like oses
- Linux / Unix: Colored Man Pages With less Command
- Linux / UNIX: Getting help with man pages and how to…
- Display Colored Man Pages in Linux and Unix
- How to install man pages on CentOS Linux 6/7/8
- How to install man pages on Ubuntu Linux
- How to add/install man pages in Alpine Linux
- Finding a File Containing a Particular Text String…
|Category||List of Unix and Linux commands|
|Firewall||Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04|
|Network Utilities||dig • host • ip • nmap|
|OpenVPN||CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04|
|Package Manager||apk • apt|
|Processes Management||bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time|
|Searching||grep • whereis • which|
|User Information||groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w|
|WireGuard VPN||Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04|
search paricular month alone using find command in linux
It should be a lowercase “k” in man -K “fopen” .
Unfortunately man -k only searches the short description. man is great if you know the specific command or the text appears in the short description. It would be nice to search the entire man system. The only way I’ve found to do that is to uncompress them or convert them.
@dj lowercase k and uppercase K are distinct options to the man command. Lowercase k searches only the short description and is equivalent to apropos, but uppercase K searches the entire content of the man pages.
for i in /*; do zgrep $i/*; done
( I arbitrarily choose i – use whatever you want). The only downside is zgrep doesn’t support -R
Oops – HTML tags bit me, that should read:
for i in /usr/share/man/*; do zgrep $i/*; done
assuming /usr/share/man is where the man pages are located, replace with appropriate path if needed.
In this guide, we’ll show you how to install npm on various Linux distributions. We’ll also show you basic usage commands for npm, such as installing and removing software packages.
In this tutorial you will learn:
- How to install npm on major Linux distributions
- Basic usage commands for npm
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the sudo command.|
|Conventions||# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ – requires given linux commands to be executed as a regular non-privileged user|
Install npm on major Linux distros
Use the appropriate command on your distribution to install npm. On some distributions, npm is installed along with the nodejs package. On others, the two packages are installed separately. The following commands will install both npm and Node.js. Feel free to omit the nodejs package when applicable, but most distributions will install it automatically as a dependency.
To install npm on CentOS 6 and 7, and older versions of Red Hat:
To install npm on Arch Linux and Manjaro:
To install npm on OpenSUSE:
Basic usage commands for npm
Here’s a list of the various npm commands you’ll likely need to know:
To see the version of npm and verify it’s installed on the system:
To install a package:
To remove a package:
To search for a particular package:
To see what packages are installed on your system:
To access the help menu and see a full list of available npm commands:
These are the all commands you’ll use when installing and removing packages, as well as searching for them by name. Check the npm help command output for further instructions, as there’s a lot more npm can do.
The ls command in Linux is used to list the files and directories in a directory. But if you wish to list directories only using ls command, what are the options?
We learn how to use command chaining (using pipes) to see what directories are present in a given directory.
In this tutorial, I will show you a number of ways to list directories only in Linux.
Listing directories using Wildcards
The simplest method is using wildcards. All the directories end in forward slash.
For the long listing, just add -l option.
Using -F option and grep
The -F options appends a trailing forward slash. So we can grep the directories only by ‘grep’ ing lines ending with a forward slash (/).
or for just the directory names, without -l option,
Using -l option and grep
In the long listing of ls i.e. ls -l , we can ‘grep’ the lines starting with d .
We can extract just the file names by printing only the last columns.
Using echo command
We can use echo command to list the entries trailing with forward slash (/).
Similarly, printf can be used to highlight strings ending with forward slash (/).
Using find command
We can always find files based on their file types using find command:
The maxdepth option in the above command specifies that the search is to be performed in specified directory only. Otherwise, find command will find the directories recursively, by traversing each directory and their subdirectories. Also, in this command, the hidden directories are also shown. In all above methods that use ls command, the same can be achieved through -a option. For example,
Thanks for reading this article. Let me know your thoughts.
Updated Nov 7, 2020
ls is one of the basic commands that any Linux user should know.
The ls command lists files and directories within the file system, and shows detailed information about them. It is a part of the GNU core utilities package which is installed on all Linux distributions.
This article will show you how to use the ls command through practical examples and detailed explanations of the most common ls options.
How to Use the ls Command #
The syntax for the ls command is as follows:
When used with no options and arguments, ls displays a list of the names of all files in the current working directory :
The files are listed in alphabetical order in as many columns as can fit across your terminal:
To list files in a specific directory, pass the directory path as an argument to the ls command. For example, to list the contents of the /etc directory, you would type:
You can also pass multiple directories and files separated by space:
If the user you are logged in with doesn’t have read permissions to the directory, you will get a message saying that ls can’t open the directory:
The ls command has a number of options. In the sections below, we will explore the most commonly used options.
Long Listing Format #
The default output of the ls command shows only the names of the files and directories, which is not very informative.
The -l ( lowercase L) option tells ls to print files in a long listing format.
When the long listing format is used, you can see the following file information:
- The file type.
- The file permissions.
- Number of hard links to the file.
- File owner.
- File group.
- File size.
- Date and Time.
- File name.
Here is an example:
Let’s explain the most important columns of the output.
The first character shows the file type. In this example, the first character is – , which indicates a regular file. Values for other file types are as follows:
- – – Regular file.
- b – Block special file.
- c – Character special file.
- d – Directory.
- l – Symbolic link.
- n – Network file.
- p – FIFO.
- s – Socket.
The next nine characters are showing the file permissions. The first three characters are for the user, the next three are for the group, and the last three are for others. You can change the file permissions with the chmod command. The permission character can take the following value:
- r – Permission to read the file.
- w – Permission to write to the file.
- x – Permission to execute the file.
- s – setgid bit.
- t – sticky bit.
In our example, rw-r–r– means that the user can read and write the file, and the group and others can only read the file. The number 1 after the permission characters is the number of hard links to this file.
The next two fields root root are showing the file owner and the group, followed by the size of the file ( 337 ), shown in bytes. Use the -h option if you want to print sizes in a human-readable format. You can change the file owner using the chown command.
Oct 4 11:31 is the last file modification date and time.
The last column is the name of the file.
Show Hidden Files #
By default, the ls command will not show hidden files. In Linux, a hidden file is any file that begins with a dot ( . ).
To display all files including the hidden files use the -a option:
Sorting the Output #
As we already mentioned, by default, the ls command is listing the files in alphabetical order.
The –sort option allows you to sort the output by extension, size, time and version:
- –sort=extension (or -X ) – sort alphabetically by extension.
- –sort=size (or -S ) – sort by file size.
- –sort=time ( or -t ) – sort by modification time.
- –sort=version (or -v ) – Natural sort of version numbers.
If you want to get the results in the reverse sort order, use the -r option.
For example, to sort the files in the /var directory by modification time in the reverse sort order you would use:
It’s worth mentioning that the ls command does not show the total space occupied by the directory contents. To get the size of a directory , use the du command.
List Subdirectories Recursively #
The -R option tells the ls command to display the contents of the subdirectories recursively:
The ls command lists information about files and directories.
For more information about ls visit the GNU Coreutils page or type man ls in your terminal.
If you have any questions or feedback, feel free to leave a comment.
Linux can seem like a very daunting environment. But it doesn’t have to be! With the two topics in this cheat sheet—the commands you’ll use on a daily basis and the useful help pages—you can easily navigate your Linux environment.
Although you can do most things in Linux these days by pointing and clicking, you still may want to try using Linux at the command prompt. This table shows you the commands that help you navigate your Linux system using only your keyboard.
|cat [filename]||Display file’s contents to the standard output device (usually your monitor).|
|cd /directorypath||Change to directory.|
|chmod [options] mode filename||Change a file’s permissions.|
|chown [options] filename||Change who owns a file.|
|clear||Clear a command line screen/window for a fresh start.|
|cp [options] source destination||Copy files and directories.|
|date [options]||Display or set the system date and time.|
|df [options]||Display used and available disk space.|
|du [options]||Show how much space each file takes up.|
|file [options] filename||Determine what type of data is within a file.|
|find [pathname] [expression]||Search for files matching a provided pattern.|
|grep [options] pattern [filesname]||Search files or output for a particular pattern.|
|kill [options] pid||Stop a process. If the process refuses to stop, use kill -9 pid.|
|less [options] [filename]||View the contents of a file one page at a time.|
|ln [options] source [destination]||Create a shortcut.|
|locate filename||Search a copy of your filesystem made at around 3am for the specified filename.|
|lpr [options]||Send a print job.|
|ls [options]||List directory contents.|
|man [command]||Display the help information for the specified command.|
|mkdir [options] directory||Create a new directory.|
|mv [options] source destination||Rename or move file(s) or directories.|
|passwd [name [password]]||Change the password or allow (for the system administrator) to change any password.|
|ps [options]||Display a snapshot of the currently running processes.|
|pwd||Display the pathname for the current directory.|
|rm [options] directory||Remove (delete) file(s) and/or directories.|
|rmdir [options] directory||Delete empty directories.|
|ssh [options] user@machine||Remotely log in to another Linux machine, over the network. Leave an ssh session by typing exit.|
|su [options] [user [arguments]]||Switch to another user account.|
|tail [options] [filename]||Display the last n lines of a file (the default is 10).|
|tar [options] filename||Store and extract files from a tarfile (.tar) or tarball (.tar.gz or .tgz).|
|top||Displays the resources being used on your system. Press q to exit.|
|touch filename||Create an empty file with the specified name.|
|who [options]||Display who is logged on.|
To access your CDs/DVDs:
- If you’re in the GUI, the media should be automatically detected.
- On the command line, look in the /media You may need to use mount/media/cdrom, /media/dvdrom, or some other variant.
To remove your CDs/DVDs:
- In the GNOME 3 desktop, right-click the CD icon and choose Eject. If you’re using the KDE Plasma desktop, select the Device Notifier icon in the Panel, then select the CD icon to eject.
- On the command line, type umount /media/cdrom, where you should change cdrom to whatever you had to use to mount the item.
Linux Help Pages
- man -k [keyword]: Search a database for commands that involve the keyword. Can also be used as apropos [keyword].
- info [command]: Display a file’s help information in an alternate format.
- man [command]: Display a file’s help information.
- whatis [command]: Display a short blurb about the command.
- openSUSE: The openSUSE documentation provides a complete reference guide to both the openSUSE environment, and the GNOME 3 desktop environment. There’s also a user forum where users can post and answer specific questions about using openSUSE.
- Ubuntu: The official Ubuntu documentation provides basic information on how to get started with most common desktop tasks. Just look for the topic area you’re interested in and follow the thread. Ubuntu also has a wiki website, where Ubuntu users can contribute their own guides and tutorials.
You can use Linux ls commands to print out directory contents. It’s one of the most basic terminal commands in Linux. Thus, a thorough understanding of it is essential for navigating your way around the terminal. Listed below are some useful examples of using the ls utility. Bookmark this as a reference point for the future.
1. Display Directory Contents
By default, the ls command displays a list of files and directories present in the current directory. You can also specify the directories using their relative or absolute path.
2. Display Additional Information
You can display any additional information about a folder’s contents using the long listing format. Simply add the -l option to your standard ls to enable long format output.
The output contains Linux file permissions, link count, owner and group information, file size, last modification time, etc.
3. Display Hidden Files
Hidden files in Linux start with a dot “.” symbol. The default command does not display these hidden files. However, you can easily view them by using the -a or –all option.
4. Classify Directory Contents
The -F option of ls allows you to classify directory contents based on their type. It appends one of the characters from the set */=>@| .
Directories are represented by /, executables by *, symbolic links by @, and so on.
5. Display Filesizes
If you want to view the filesizes only, use the -s or –size option. Note that the size information is displayed in blocks, the same as Linux du commands.
6. Display Human Readable Filesizes
Both standard ls and the ls -s command prints the filesize in blocks. Add the -h option to display this information in a human-readable format.
7. Sort Output by Modification Time
You can use the -t option of ls to sort directory contents based on the latest modification time. Add the -l flag to retrieve more information.
8. Sort Output by Size
Use the -S option of ls for sorting the output by their respective sizes.
9. Display Files Using Patterns
You can use bash wildcards with ls commands for displaying files based on a pattern. For example, the following command displays only mp3 files.
10. Hide Files Using Patterns
We can also hide files or directories based on a predefined pattern. The following examples display all files except for mp3 tracks.
11. Display UID and GID
Linux systems use UID (User Identifier) and GID (Group Identifier) for identifying users and groups. You can display this information for all your files using the options -n or –numeric-uid-gid .
12. Display Subdirectory Contents
By default, ls doesn’t display contents that are stored inside subdirectories. However, you can use the -R or –recursive option to override this. The below example showcases this.
13. Display Directories Only
You can use the -d option followed by a bash pattern for viewing all sub-directories inside a folder.
14. Display Help Page
The help page of ls contains summarized information on all available options. Use this whenever you need to find out a specific option.
15. Display Manual Page
You can consult the man page to find out detailed instructions on all ls options and how to use them.
The ls utility is one of the most simple yet versatile navigation tools in Linux. You can’t really master the Linux command line unless you’re comfortable with ls commands. Luckily, it’s easy to pick up this command once you understand some basic examples like the ones shown in this guide. Check out other ways to list the content of a directory in a Linux terminal.
Rubaiat is a CS graduate who possesses hands-on experience with Unix Administration, Web Programming, DevOps, and Virtualization. He has a strong passion for enlightening people in open-source technologies.
In this article, I will show you how to list all running services on Linux. We will also check how to check the status of a service on a systemd system.
Let’s learn different commands used to list services on Centos/RHEL 7.x.
Check and Listing linux services (systemd on Centos/RHEL 7.x)
To list systemd services we will use systemctl command as below
To list active systemd services run
Another command you can use is
You can pipe the output to grep to search a more specific service as shown below
Listing services using Netstat Command
Nestat command is a tool used for examining active network connections, interface statistics as well as the routing table. It’s available in all Linux distributions and here we will check how to list services using netstat command.
To check the services alongside the ports they are listening.
Viewing /etc/services file
The /etc/services is an ASCII file that contains information about numerous services that client applications might use on the computer. Within the file is the service name, port number and protocol it uses, and any applicable aliases. ITO put t indicates whether a service is TCP or UDP and the name it goes by according to IANA. This information is helpful especially if you are unsure which service is running on which port by default.
To get a clearer picture, view the /etc/services file using a text editor of your choice.
Systemd services status check
In newer versions of Linux, Systemd init is present. To check if a service is running, use the syntax below
For example, to check if OpenSSH is running on your system, run
Alternatively, you can use the syntax below to check if the service is active
In this case, to check if OpenSSH is active, execute
Also, you can use the command below to check if a service is enabled
To check if OpenSSH is enabled, run
Checking the status of services in older systems (Centos/Rhel 6.x)
For systems running SysV Init, you can check the status of services by running
For example, to check the status of OpenSSH, run
You can also check all services by running
We hope you found this article useful. Feel free to try out some of the systemd commands listed here.