Basic linux commands

Note
This article was last updated on 2024-06-22, the content may be out of date.

Happy 30th birthday, Linux! Thirty years ago, on August 25th, 1991, 21-year-old Finnish student Linus Benedict Torvalds made his now-famous announcement on the comp.os.minix news group, saying that he’s working on a free operating system for 386(486) AT clones, just as a hobby.

Hello everybody out there using minix – I’m doing a (free) operating system (just a hobby, won’t be big and professional like gnu) for 386(486) AT clones. This has been brewing since april, and is starting to get ready. I’d like any feedback on things people like/dislike in minix, as my OS resembles it somewhat (same physical layout of the file-system (due to practical reasons) among other things).

I’ve currently ported bash(1.08) and gcc(1.40), and things seem to work. This implies that I’ll get something practical within a few months, and I’d like to know what features most people would want. Any suggestions are welcome, but I won’t promise I’ll implement them 🙂 Linus

PS. Yes – it’s free of any minix code, and it has a multi-threaded fs. It is NOT portable (uses 386 task switching etc), and it probably never will support anything other than AT-harddisks, as that’s all I have :-(.

Thirty years later, as you can already guess, the little hobby project called “Linux” now runs the technology world. To celebrate this milestone, I’m listing the thirty basic/most-used commands on GNU/Linux operating system.

Side note: this is also requested by a friend of mine on Threema called Niko 🙂. Click to view the messages:

Messages
Messages
Threema messages from Niko
Command Description
cat Display file’s contents to the standard output device (usually your monitor).
cd 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 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.
who [options] Display who is logged on.

Here are some other terminal commands that you may find helpfull.

curl is a “command line tool and library for transferring data with URLs.” It is a handy multitool that supports many network protocols. Some basic commands are:

  • curl --head [domainname] displays HTTP response headers (including security-relevant headers).
  • curl --header '[header]' [domainname] adds the ‘[header]’ to your request.
  • curl --insecure https://[domainname] connects to the domain and ignores any certificate errors.
  • curl --sslv3 https://[domainname] connects to the domain using insecure SSLv3 (also works for other insecure SSL/TLS versions).
  • curl -u user:password -O ftp://domainname/file downloads a file using username and password authentication via FTP.

dig is part of BIND and can be used to check domains for DNSSEC:

  • dig [domain-name] +multiline
    • “status” should be “NOERROR” (“SERVFAIL” means that there is a problem with the DNS server configuration, e.g., DNSSEC configuration is broken)
    • “flags” must contain “ad” (authentic data)
  • dig [domain-name] +multiline +dnssec
    • This query sets the “DNSSEC OK” (DO) bit and requests DNSSEC records to be sent, if available
    • Look for “RRSIG” resource records
  • dig [domain-name] +trace
    • This query emulates a DNS resolver. It starts from the root of the DNS hierarchy and works down using iterative DNS queries.

Well-known tools use imagemagick, so it is likely that imagemagick is already installed on your machine. You can use it to remove metadata from photos:

  • Remove metadata: mogrify -strip [filename]

    • “-strip” means “strip the image of any profiles, comments or these PNG chunks: bKGD, cHRM, EXIF, gAMA, iCCP, iTXt, sRGB, tEXt, zCCP, zTXt and date”
  • View metadata: identify -format '%[EXIF:*]' [filename]

pwgen is a password generator:

  • Create passwords containing upper-case and lower-case chars, digits and special chars:

    pwgen -scyn1 [number-of-characters] [number-of-passwords]

  • Create passwords containing upper-case and lower-case chars and digits: pwgen -scn1 [number-of-characters] [number-of-passwords]

qrencode can be used to transform arbitrary strings into QR codes:

  • qrencode -o [qr-filename].png '[string]'
  • Change the pixel size: qrencode -o [qr-filename].png -s [pixel-size] '[string]'

subnetcalc is a CLI-based calculator for subnets of IPv4 and IPv6 networks.

  • subnetcalc 192.168.1.1/24 prints network, netmask, broadcast address, max. hosts, properties, and more.
  • subnetcalc ashpex.eu.org prints IP addresses, properties, geo-information about the IP address, and more.