Check out my books on Amazon at https://www.amazon.com/John-Au-Yeung/e/B08FT5NT62
Subscribe to my email list now at http://jauyeung.net/subscribe/
Linux is an operating system that many developers will use.
Therefore, it’s a good idea to learn some Linux commands.
In this article, we’ll look at some useful Linux commands we should know.
head
The head
command outputs the first few lines of a file.
The -n
flag specifies how many lines to shows.
The default number of lines to show is 10.
tail
tail
outputs the last few lines of a file.
We can also use the -n
flag to specify how many lines to show.
Also, we can get the end of the file beginning with the N
-th line with:
tail -n +N
cat
cat
concatenates list of files and send them to the standard output stream.
less
less
is a quick tool to let us view a file.
It opens up the file content with a read-only window.
nano
nano
is a small text editor.
It’s easy to use for beginners since we don’t have to learn lots of shortcuts.
nedit
nedit
is a small graphical rextr editor.
And it lets us edit text with point and click, drag and drop, and syntax highlighting.
touch
touch
lets us modify the timestamp of an existing file and quickly create a new file.
logout
logout
lets us exit the shell we’re logged into.
ncdu
ncdu
lets us display file space usage.
It opens a window that shows the disk usage of each file.
top
top
displays all currently running processes and their owners, memory usage, and more.
htop
htop
is an interactive version of top
.
We can pass -u username
to display processes that are owned by user username
.
whereis
whereis
lets is search for files related to a particular command.
For instance, we run:
whereis ls
to find the path to the ls
command and the associated manpage.
whatis
whatis
prints the description of the command from its man page.
locate
The locate
command finds a file anywhere in the system by searching a cached list of files.
find
find
iterates through the file system to find the file we’re looking for.
It looks at files that currently exist in the system.
find
lets us search by file age, size, ownership, type, timestamp, permissions, depth within the file system, regex, and more.
wget
wget
lets us download a file from the Internet
curl
curl
can be used like wget
, but we need the --output
flag.
curl
supports many moe protocols and it’s more widely available that wget
.
wget
can only receive data, but curl
can also send data.
wget
can download files recursively, but curl
can’t.
apt
The apt
command is available in Debian based distros.
It can be used to install, upgrade, or delete software on our machine.
We can run apt search
to search for packages. apt install
lets us install packages.
Conclusion
Linux distros comes with many commands that we can use to manage files and download files.