Linux & Android > Articles, Tutorials and Tips

Favorite CLI commands

(1/3) > >>

I knew most of you use the CLI (command-line interface), otherwise known as the terminal, on at least a semi-regular basis, right? Tell me I'm right. :D If I'm already named something, feel free to mention it anyway. I'm thinking we might learn a few new commands or just that the capability is there.

Anyway, thought it might be interesting to share what terminal commands we use the most. Some of these I use on the desktop, some on the server (PLUG server usually).

--- Code: ---$ sudo apt update
$ sudo apt full-upgrade
--- End code ---

Linux Lite handles updates fairly quickly but doing it in the terminal still feels faster. And have to use this for the server; no graphical environment.

--- Code: ---$ df -h

--- End code ---
- lists free space (df = disk free) as well as capacity and used space on your partitions including virtual and loopback ones
- the -h is for showing it in human form, so instead of 123456 bytes, you get 123 KB, etc.

--- Code: ---$ kill <PID>
$ kill -9 <PID>
--- End code ---
- kills a process (PID=Process ID) - you can do this graphically, too, but it's easier to do it this way if you need superuser privileges
- kill by itself is a graceful shutdown while -9 means to kill with extreme prejudice - forced to shut down no matter what

- to find that PID, you will need to use another command such as...

--- Code: ---$ ps -e | grep <progam/process name>
--- End code ---
- ps by itself only gives the processes running owned by the current user IN the terminal
- using -e shows all commands by the current user and I pipe that output to grep with a program name because there are a LOT of processes running

--- Code: ---$ less <filename>
--- End code ---
- good for looking at a file showing one screenful at a time; hitting any key goes to the next screen
- also good for piping output of another command to it

--- Code: ---$ nano <filename>
--- End code ---
- good for editing a file

--- Code: ---$ free -h
--- End code ---
- shows free, used and shared memory as well as used swap
- the -h does the same thing as with the df command

--- Code: ---$ htop
--- End code ---
- better than top - shows processes running, one program can spawn multiple processes

--- Code: ---$ man <program>
--- End code ---
- gives in-depth info about a command-line program and/or configuration file
- can use -h (sometimes --help) to get usage info and a list of options possibly with basic info about what they do

--- Code: ---$ file <filename>
--- End code ---
- tells you the format of a file, e.g. ASCII, and possibly lots of other info
- good for knowing what the heck something is and just kind of cool

--- Code: ---$ which <program_name>
--- End code ---
- tells you where a program is located; could be multiple locations

Obviously, I also use ls, mdkir, mv, rm, rmdir, etc. For most desktop users, you might not need the terminal at all but I think every Linux user should know a few, if only to fix things when your GUI doesn't work.

Several of mine overlap with yours, Jason, but one missing that I use a lot is

--- Code: ---uname -r
--- End code ---

... to tell me what kernel I'm running.

--- Code: ---ls
--- End code ---

--- Code: ---cd <directory I want to change to>
--- End code ---

--- Code: ---rm -R <folder I want to delete>
--- End code ---

I actually didn't think about using '-r' with rm. I've used 'rm -rf' plenty of times. Dangerous commands!

Whenever I'm going to erase a set of files using a wildcard, I always do 'ls' with the parameter I intend to use in 'rm -rf' so I don't screw something up. Linux will quite happily erase your entire file tree if you have superuser permission and run... for a while. For example, before running:

--- Code: ---$ rm -rf file*
--- End code ---

I run:

--- Code: ---$ ls file*
--- End code ---

Sometimes you think a wildcard will just match certain files and it matches a lot more!

I use uname -r, too. And that reminded me of another one:

--- Code: ---$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal

--- End code ---

Some distros, I'm looking at you Fedora, don't seem to come with this tool. But it's easy enough to get.

"I knew most of you use the CLI (command-line interface), otherwise known as the terminal, on at least a semi-regular basis, right? Tell me I'm right. :D "

In Windows or in Linux I use the command line only when necessary. There is usually a method without command line. I read again today a comment in a magazine that Linux should never be recommended to anyone unless they are technically competent to use 'text commands'. This is so much horseshit.

Linux can be installed and run by relatively non-nerdy people, just as Windows and Mac can be. This should be advertised and practised. And I am the prophet, coming from the east, who shall lead the way.  :)

I mentioned above, Buster, that desktop users generally won't have to use the CLI. That doesn't mean there aren't good reasons to do so sometimes.

Some programs, like VMWare, ProtonVPN and Private Internet Access VPN require using the command-line to install/uninstall. But the information is given so it's not hard to do. Ctrl-C + Ctrl-V and you're done. Well, if you know how to find the terminal on your machine, it is. :) Btw, Ctrl-C + Ctrl-V is a combo EVERY computer user should know (I think it's slightly different on the Mac). It's one of those things that some people are surprised to learn that can same them a lot of time. Also, with some programs, it's the only way to paste elements into it.

We didn't mention it but it seems like most graphical updater programs don't remove packages that are no longer needed. But running this command will:

--- Code: ---$ sudo apt autoremove
--- End code ---

I think Bill ran it once under Linux Mint and it gave him back a gigabyte of disk space. Try it yourself and see how much you get back. If you're been using the distro for a long while, it's likely a lot. Sure, drives today are big but some people are still using computers with small, or nearly full drives already (gamers, torrentors, etc.). There are probably graphical programs that do this. But in terms of time use, is it faster to find such a program, install it and then have to run it, let it load and find the menu item that does it or just run that command which takes a few seconds?

Honestly, I think most people that have encountered Linux know they don't have to run terminal commands but, like with Windows, you can't call yourself a Linux guru or even an advanced Linux user w/o knowing some. I agree that a desktop-user of Linux will rarely if ever have to use the CLI. You're just a better Linux user if you do and can't count yourself as a real guru. There are a lot of Windows tricks that you can do with Powershell, too.

The main reason more people don't use Linux is inertia. They won't change because Windows works "good enough" and they don't know there are OSes that handle the drawbacks they put up with. Or because they're used to the programs in Windows and they're not available in Linux (i.e. MS Office). Of course, LibreOffice is great but if you need to share files with others (who are addicted to MS Office), it's still not 100%.

But people who have never used a computer find Ubuntu Desktop very easy to use. Unfortunately, there's not a lot of those people. I don't know if there is anything you can do to get those users (the vast majority) to even try Linux any more than you can convince the anti-vaxxer crowd to get their damn shots.


[0] Message Index

[#] Next page

Go to full version