Introduction to the Unix / Linux command notebook
I first used Unix over 20 years ago when I was at college. After that I got my first job and the company were then taking out their old Unix based system and were replacing it with a big IBM S/36 system which was later upgraded to an AS/400. Along the way we saw DOS and Windows come and go.
Now here we are in 2022 and although AS/400 and Windows are still very important the systems which I spend most of my time managing today are Unix based; I can’t help feeling technology has gone around in a circle.
As I was getting back up to speed with Unix after all these years I’ve been keeping a few notes which I’ve typed up below as a common Unix commands cheat sheet. I’ll be adding to this list from time to time as I find something else useful that I want to make a note of.
For practical purposes you can treat this page as a Linux basic commands cheat sheet as well. Where I am aware things work differently between Linux, Unix and MacOS BSD then I try and call this out below.
If you have any comments please get in touch.
Running commands as the Super User
It is best practice to be logged on with the minimum authority required to perform your work. This isn’t just true on Linux but any computer platform. There are a few reasons for this. a) If your user id and password were to become known to someone else the possible damage would be limited to whatever your user id is authorized to do b) If you visit a website or receive an attachment containing a virus, then the damage that it can cause is limited to whatever your user id can do. Never get into a habit of logging on as Root or Administrator for your day to day work.
In Linux to Open a command window (right click on the desktop and select Open Terminal if you’re running a GUI).
The terminal will be logged on using your current user profile.
When you need to install a new package or change configuration you can switch to Super User mode by using the su command. This will prompt you for the password of the root user profile. Once you supply the correct password your terminal window will then be logged on as the root / super user.
Useful sources of installation, boot log files and configuration information for your Linux server.
In /var/log you should find a file called boot.log, this can be displayed by using the command
People from an AS/400 / iSeries / i5 background can think of this in terms of using DSPLOG to view the history of the last IPL.
In /root you should find a file called install.log this lists all of the installed packages and lists in errors found during the install.
dmesg (equivalent of OS/400 WRKHDWRSC) lists detailed information about your systems hardware configuration.
What is the Linux equivalent of the Windows IPCONFIG or OS/400 CFGTCP command?
The nearest equivalent of the OS/400 CFGTCP command I have found so far is /sbin/ifconfig
How do I connect to my Linux server for admin purposes from a Windows system?
We have Linux running on Servers but Windows on the desktop. To save walking to the Linux servers console use a Secure Shell (ssh) client. Windows does not ship with an ssh client so you will need to download a free client. See http://www.ssh.com/products/tectia/ or download directly from ftp://ftp.ssh.com/pub/ssh/
From Windows you can then use the ssh client to connect to your Linux server.
How do I connect to my Linux server for admin purposes from a Mac OSX / MacOS system?
On the Mac OSX comes with a built in SSH terminal application.Â Â Just search for Terminal using Spotlight or locate it manually in the Applications directory.
What is the Linux equivalent of WINZIP / PKZIP / PKUNZIP or the OS/400 AS/400 Save File (*SAVF)?
The command gzip is an Open Source Linux equivalent. You should note that unlike on Windows or DOS the Linux ZIP process happens in two steps. First the files are packaged together into a single file using the tar utility and then the tar file is compressed using gzip.
gzip -d <filename> will uncompress the file to the current directory
tar -xvf <filename> will unpackage the tar file into the current directory. (X=Extract, V=Verbose, F=Filename)
The tar command lets you combine these two steps into a single command…
tar -xvzf <filename> this command will extract the tar and unzip it in one step.
How do a run an executable script file from the terminal window?
You need to type ./<filename>
How do I get more information about commands?
How do I find files on my Linux server?
Use the locate command eg
locate <filename / wildcard>
Common Linux file management commands
mkdir – Make directory
rm – remove/delete a directory / file
cp – copy eg cp <source> <destination>
mv – move file. This is also used to rename a file.
ls | more – list contents of directory a page at a time
ls | less – display contents of a directory in a scrollable list
tail <filename> – displays the last 10 entries in a file
ls >inventory.txt – outputs the results of the ls command to a text file called inventory.txt. If the file already exists it will be overwritten. To append to the end of an existing file use >> for example ls >>inventory.txt
ls -al – this lists the directory and shows the files, directories and access rights.
File Level Access Rights
Set a file to read-only.
chmod u=rwx,grwx,o=rwx <file> -R chmod
Linux text file editor commands
There are numerous editors available including nano (which seems similar to WordStar in the CPM days!) but the one to master is vi. (Although as of 2021 you will probably find Nano widely installed and it’s a lot easier to use.)
Use the cursor keys to move around the file. To insert new text press the INSERT key on your keyboard, when complete press ESCAPE to go back to navigate mode.
When in navigate mode you can enter commands. The most useful commands are:
:w – write or save the file
:q – exit
:q! – exit without saving
/<string> – find string
/ – next result
These days I tend to prefer the Nano editor if I’m working with large files on a Linux Server.
Grep linux – Search files
It’s often useful to be able to search large text files or log files; for example to find error messages or an IP address in a log file. To do this use the grep command.
grep 172.16.1.1 access_log |more
This will search the access_log file for the IP address and pipe the output to the more command so that you can page through the results.
How do I see my command history log (equivalent of f9 on OS/400)
Try the history command. This will show you the last 100 or so commands you have run. You can also use the cursor up and down arrow keys from the console to scroll forward and back through your command history.
What is the equivalent of the AS/400 WRKOBJLCK command?
What is the equivalent of the AS/400 WRKJOB command?
lsof -p “process id”
How can I count the number of files in a directory?
ls -lh /my-directory-name/ | wc -l
This command will list the chosen directory and then pipes the output the wc utility which we set-up to count the number of lines. You could also use this approach to count the number on lines in a text file.
What is the Linux equivalent of AS/400 SBMJOB command?
In Linux, the nohup command basically submits the job to batch processing. It’s maybe more like the S/36 Evoke command as it the job goes directly into processing without joining a job queue first.
For example if we type:
nohup ls -al
the ls -al command will be submitted to batch processing. You will see a message that the standard output is being redirected into nohup.out in your current directory.
You can monitor this with:
tail -f nohup.out
What is the Linux equivalent of AS/400 WRKUSRJOB and WRKACTJOB commands?
The ps ax command
To get a full list of all the jobs which are running and the command which launched them:
This will give you some output like this:
PID TT STAT TIME COMMAND 1 ?? Ss 51:01.15 /sbin/launchd 79 ?? Ss 22:40.40 /usr/libexec/logd 80 ?? Ss 7:03.79 /usr/libexec/UserEventAgent (System) 83 ?? Ss 0:19.25 /System/Library/PrivateFrameworks/Uninstall.framework/Resources/uninstalld 84 ?? Ss 16:44.38 /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Versions/A/Support/fseventsd 85 ?? Ss 1:27.26 /System/Library/PrivateFrameworks/MediaRemote.framework/Support/mediaremoted 88 ?? Ss 1:53.87 /usr/sbin/systemstats --daemon 89 ?? Ss 1:30.19 /usr/libexec/configd
You can search this to find specific jobs using the command:
ps ax | grep “Google”
In this example, we pipe the ps ax command into grep and then search for any jobs containing the name “Google”.
The top command
This is very similar to WRKACTJOB, it shows you all the active jobs in an automatically refreshed view and also shows which are using the most processor time.
top - 21:39:21 up 8 days, 11:52, 1 user, load average: 0.15, 0.14, 0.21 Tasks: 156 total, 2 running, 154 sleeping, 0 stopped, 0 zombie %Cpu(s): 2.8 us, 1.0 sy, 0.0 ni, 95.5 id, 0.2 wa, 0.3 hi, 0.2 si, 0.0 st MiB Mem : 7961.3 total, 2247.5 free, 849.4 used, 4864.3 buff/cache MiB Swap: 0.0 total, 0.0 free, 0.0 used. 6676.6 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1972946 jg-admin 20 0 437028 58032 21672 S 3.7 0.7 4:01.44 python 6972 nxautom+ 20 0 481056 26252 10204 S 1.0 0.3 16:19.81 python3
The screen is sorted, so that the job using the most CPU is at the top.
Whereas WRKACTJOB would only show you the current CPU %, the Linux top command shows you the load average. Here we see 3 figures
0.15 – the average load over the last 1 minute
0.14 – the average load over the last 5 minutes
0.21 – the average load over the last 15 minutes
The nproc command should tell you how many processors are available on your machine. (MacOS is BSDUnix but most of what we discuss here still works the same, however the nproc command isn’t supported on macos, instead use the command sysctl -n hw.ncpu to see how many processors you have)
If this is 2, then 0.15 is low, but 1.99 would be high.
I would say that the Linux top command isn’t as friendly as WRKACTJOB but it’s probably (debatable) more powerful.
Any Linux Questions?
If you are looking for specific Linux commands please leave a question below.If you have any good additions to my Linux server commands cheat sheet please leave a comment below.