Linux Commands FAQ
last update:8/29/2021
This page is always under development. As we learn more helpful
Linux commands and tools, we'll add them to this list. This
page is a way to help us manage the large amount of Linux specific
material covered.
Reminder: lots of information at our Linux
Web Page
Items will at least initially added in an order of most
recent at the top (and oldest at the bottom).
If you discover something helpful on your own, please
contact the course staff so it gets added.
Topic 1
How can I find all files ending in "*.c" ?
find . -name "*.c" -ls
How can I delete all files ending in "*.tar" ?
find . -name "*.tar" -delete
What is the difference between adduser and useradd in
Linux? (See
https://unix.stackexchange.com/questions/121071/what-does-adduser-do-that-useradd-doesnt)
adduser and addgroup add users and groups to the system
according to command line options and configuration information
in /etc/adduser.conf. They are friendlier front ends to the low
level tools like useradd, groupadd and usermod programs, by
default choosing Debian policy conformant UID and GID values,
creating a home directory with skeletal configuration, running a
custom script, and other features
Topic 2
- Try the commands 'lshw', lscpu, lsusb to see
detailed info about the system. Issue a 'which lshw' to
find where the binary is located. Then try 'ls /usr/bin/ls*'
to see many interesting ls * commands to learn
about the platform.
- The follow great idea was contributed by Tom Randall, CSPC8510
Fall 2020)
Instead of
manually timing 3 minutes you can use the following preposition
to your unix command:
timeout -s 2 3m <your normal command here>
timeout -s 2 3m ./client <ip> <port>
<iteration delay> <message size> <# iter>
<debug level>
Topic 3
- df -T ;shows the filesystem structure
- Try 'cat /etc/fstab' to see the commands run at
boot time that setup the file system
- mount shows similar info
- See also findmnt
Topic 4
In our git repo in /bin look at bex1.sh. This script
is passed one param: a file name. It then gives information
about that file.
- One thing to keep in mind....you can enter a script by hand,
line by line. Obviously a script is all about automating
work tasks on a Unix system.
- On a command line: you can enter > 1 command to be
processed sequentially : 'cd ~/devel/myProject; ls
-lt *.c; make clean; make all;'
- This is very different from a pipeline
: 'cd ~/devel/myProject; find .
-name "*.c" -ls | wc -l'
#shows a count of number of files found
- 'cd ~/devel/myProject; find . -name "*.c" -ls | md5sum
' # computes a single md5 hash from all files
- Line 23 : echo "Size is $(ls -lt
$FILENAME | awk '{ printf $5 }')"
- Let's break this apart:
- The job of '$(_ )' is to run the
script withing the ()'s and return the result.
Note that everything in bash deals with strings.
- $FILENAME will be replaced by the value of the variable
FILENAME (which is set before with the filename).
- On your terminal try the following
- FILENAME=bex1.sh
- echo " the file: $FILENAME "
- ls -lt $FILENAME
- All of the above should work as we have set the variable
FILENAME in the current bash environment
- The () is a pipeline: this is two or more valid bash
commands separated by a "|" pipe character.
- The way bash works when it encounters "ls -lt
bex1.sh | awk '{printf $5}'"
- It parses the pipeline into sequential components
- First it forks a process that will
eventually run "ls -lt bex1.sh"
- It forks a second process, and sets the first process
output descriptor with the input file descriptor of the
second process - this redirects the output of process 1 to
the input of process 2
- It uses the exec function to setup the second process to
run the awk program
- It uses the exec function to setup the first process to
run the ls program
- Process 1 runs, generates 1 line of output.
- Process 2 receives the line of input, which is input to
the awk program. This simple example of awk
will just print the 5th element in the string passed into
it. By default, strings are parsed by awk into
fields using the space character as the delimiter.
- We then looked at the systemMonitor.sh program.
- systemMonitor.sh SYSINFO enp0s3 1 0 1
; SYSINFO is just a label. The next
parameter must be a valid network interface name. The next
param is the frequency the script should run, the next is
the number of iterations (0 implies forever) and the last
param designates where the output is to go.
- THe script produces lines out output - each line is a
sample of the systems 'health'. The output
consists of 4 major pieces of info:
timestamp loadavg IP address rx/tx
throughput for the current interval
- Each loop iteration does the following
- Computes the rx and tx throughput for the interval
- obtain the loadavg
- obtain the current UTC time
- display the output in a single line
- The iteration delay (a parameter) is the sleep performed
after the rx and tx byte counts and current timestamp are
obtained
- After the sleep, it obtains another byte count sample
and a second timestamp. The throughput is defined as
the number of bits sent or received during the sleep
interval.
Topic 5
A Unix shell program is a terminal based UI to the system.
There are MANY different shell programs for Unix. Luckily the
world of Linux is converging to bash.
Issue a 'man bash' - don't be
intimidated! The bash shell is similar to matlab and
python in that it provides a very complete and complex
work/programming environment to do things like automate work to be
done on a Unix system, analyze data, monitor the system.
Issue from a terminal 'man man' - man is
Unix's online help/documentation. Most systems also have
the 'info' tool which also provides information.
For man, note there is a param called section
number. Certain commands map can map to different
things. Let's use the command 'kill' as an
example. Issue 'ps aux' to see all the
active processes. To see just your's 'ps u'. The
second column shows the process id. You should have access to
a script loop.sh (in ./bin). Issue from one term
'loop.sh'. In another term issue 'ps
u' The ps command gives certain information
by default....information such as %CPU %MEM is typically very
helpful as you can find the applications that are possibly making
your system slow. Even better tools to do this:
top, 'vmstat 1' , and mpstat (the latter
might need to be installed by 'sudo apt install sysstats'
0. Once you know the PID (in our example
assumpe loop PID is 13445. You can kill the 'loop.sh'
script with a CNT-C OR, from another term, issue 'kill
13445'. The kill unix program is super
useful as it allows you to issue a signal to any process.
Issue 'man kill' for details. The complication is that
the kill function can be done in your "C" progorams - therefore
another form of kill is as a system library call. A 'man
kill' only shows the unix program kill information.
An extremely helpful program is apropos. Issue 'apropos
kill' - this has the system search to find all likely programs
that have the work 'kill' in it. It also shows all other uses
of 'kill'. Issue 'man 2 kill' to find the
syntax for the programming interface description to the kill system
call.
Topic 6 A copy/paste from a
previous class Slack channel involving questions and
answers that might be helpful
Tom:jebplz: 12:21 PM
was added to #linuxtopics by Jim Martin, along with 12 others. Also,
Chinmay Rathod joined.
Jim Martin 12:49 PM
Hi all, see the updated course web page. For windows users, I
suggest you follow the page I've added to install the Ubuntu 18.04
windows 10 app.
Ebuka Okpala 8:23 PM
joined #linuxtopics.
Bennett Meares 5:54 PM
If anyone is having trouble using sftp, you can download the .ova
file with this command:
scp -P 5555 -oKexAlgorithms=+diffie-hellman-group1-sha1
cpsc8510@cybertiger.clemson.edu:~/CPSC8510.ova ~/
:raised_hands:
2
Shaurya Panthri 6:18 PM
joined #linuxtopics.
Pinned by Tom
Bennett Meares 6:40 PM
Does anyone know where I can find the VM root password?
edit: password is cpsc8510 (edited)
Manveen Kaur 6:41 PM
Bennett, are you trying to access as root? If so, you can do ‘sudo
su’ from within the VM with your VM password.
Jim Martin 2:59 PM
Random but super useful tool in Unix to find files. Let's say
we want to find all files ending in "*.c" that have changed in the
last 24 hours. The following pipeline should work
(type this or copy/paste into a terminal on your VM) : find .
-name *.c -mtime -2 -type f -ls | awk '{print
$11}' In our
git repo (I'll send the git clone link tonight) there is a
subdirectory ./bin which contains a number of userful bash
scripts. One is filesUpdated.sh which finds files that have
been modified within a given number of
days. Bash is the default shell
program that forms a ascii terminal based interface to Unix.
On windows, the command prompt and the PowerUsers Command Shell are
equivalent (but very very different syntax). That's why I like
the Ubuntu 18.04 App on windows 10....it gives me a fully functional
bash shell environment on top of windows. Regards, Jim
:+1:
1
Bryson Rudolph 4:39 PM
I apologize if this is obvious, but does anyone happen to know if
there is an easy way to specifically install iperf v. 2.05 using
sudo? I’ve tried “sudo apt-get install iperf_2.0.5+dfsg1-2_i386.deb
-V” but I get an error. Thanks! (edited)
Larry Fuller 4:41 PM
only way i’ve found to do it was to manually compile....also looking
for the easy button if anyone knows :)
4 replies
Last reply 2 months agoView thread
Tom:jebplz: 8:20 AM
You can also visit the iperf website in your VM browser and let the
Ubuntu software app install it from there
Tom:jebplz: 10:16 AM
Does anyone with an OSX host have bidirectional clipboard
(copy/paste between host/vm) working? Mine doesn’t work--only a
minor inconvenience but one I’d be very happy to resolve.
Larry Fuller 1:35 PM
you have to enable the vbox option to mount the guest additions
pack, which mounts a CD image on the guest. once that’s done,
browse to the guest cd drive and install the guest pack. @Tom
https://www.virtualbox.org/manual/ch04.html (edited)
:+1:
1
Jim Martin 6:18 PM
Good question related to installing iperf v2.05. At this
point, there are three versions of iperf. To check what has
been installed on the VM with apt, issue
'sudo apt-cache pkgnames | grep iperf'. I see 2
versions, iperf and iperf3. You can also
issue 'locate iperf' to find executables (it will find lots of other
things with that string). You can also issue 'which iperf' to
see where it is located. Issue 'iperf -v' to see what
version. Our original VM has iperf version 2.014.
Then I recommended you go back to iperf 2.05. You
should be able to issue 'sudo apt install iperf' ....
use which and the iperf -v to make sure it's
v2.05. I forget where it gets installed. But I ended up
installing all three versions on my VM. I located them in
/usr/bin. On my system there are : iperf,
iperf2, iperf3.
Jim Martin 6:25 PM
oops... sorry, hit enter by mistake. If i issue
'iperf -v' 'iperf2 -v' and 'iperf3 -v' i see
2.05, 2.014 and 'iperf 3.0.11'. So install iperf 2.05
with apt. I installed iperf2 by downloading the iperf v2.014
from the Internet (at ). And I did 'sudo apt
install iperf3' to get v3. I found each iperf, and renamed as needed
placing iperf, iperf2, iperf3 in /usr/bin. After I build
iperf2, i issued the following: 'cd ./iperf2-code/src'
and then 'sudo cp iperf /usr/bin/iperf2. My
favorite is iperf2 but we ran into issues running iperf2 on
cybertiger. That's why we had to switch back to iperf 2.05.
This writeup provides insight in the differences across the three
versions:
https://iperf.fr/iperf-doc.php.
Let me know if this was confusing..... bottom line - you
just need iperf 2.05 on your VM.
---Jim
iperf.friperf.fr
iPerf - iPerf3 and iPerf2 user documentation
iPerf3 documentation - measuring TCP, UDP and SCTP bandwidth
performance
Jim Martin 2:38 PM
Just an FYI, I periodically run the script from
~/bin/findBiggest.sh to find large files. Then I'll
delete the largest files that I know I don't need. When we start
using ns3, it's likely that you will produce very large trace
files.
2:40
The two step process: 1. findBiggest.sh .
10000k and let's say this shows a bunch of
large files ending in .out or .tr, to
delete: find . -name ".out" -ls
to double check, and then find . -name ".out" -delete
Jim Martin 8:40 PM
Contributed by Tom Randall :
8:40
Instead of manually timing 3 minutes you can use the following
preposition to your unix command:
timeout -s 2 3m <your normal command here>
ie: timeout -s 2 3m ./client <ip> <port> <iteration
delay> <message size> <# iter> <debug level>
Jim Martin 9:03 PM
We have been introduced to the Linux traffic control. To see
the current settings issue : 'sudo tc qdisc show' . The
default settings differs on 16.04, 18.04, and 20.04. For
16.04, you should see a qdisk for pfifo_fast - the default first
come first served queue. On our 18.04 appliance, you will
notice something very different. The default queue management
is managed by fc_codel and the AQM's default params are
shown. We will be learning about AQM and using it in both ns3
and on Linux systems.
9:04
Two ways to compare two versions of a source code path. Let's
says there are two directories:
~/devel/mysourceV1 and ~/devel/mysourceV2. Two
easy ways to determine what files differ Issue cd
~/devel. And then method 1: diff -q ./mysourceV1
./mysourceV2. method 2: md5sum
./mysourceV1/.c ./mysourceV2/*.c. The tool
md5sum will list the md5 hash of each "C" file makeing it easy to
find files that are different. I also use md5sum
regularly to validate the integrity of
backups. You probably have notices
that, for example, if you download a large file such as an ISO, the
source web site usually identifies the md5 hash. You
would run md5sum on the files downloaded and compare to the listed
md5hash. An md5hash is a widely used method to
produce a /'fingerprint' of one or more files. The odds are
extremely low (essentially 0) that two different files can produce
the same hash. There are two critical properties of a
userful hash, especially a hash that is used for crypto
purposes. 1. The has is 'one-way' meaning it is
computationally infeasible to a 'malicious' node to generate
portions of the source files based just on the hash and knowledge of
the hash technique; Second, the probability of a 'collision'
is about 0. A collision occurs when two different messages or
files end up with the same md5sum value. (edited)
Jim Martin 9:37 PM
Two helpful tools in Linux: 1.
arp-scan ('sudo arp-scan --interface wlp4s0
192.168.1.0/24 #this will issue arp 'whois' for all 255
hosts on network 192.168.0/24. It shows the mac address and
bound IP address along with information about the
platform. 2. A second
tool: nmap. You can use it like arp-scan to
find all active hosts on the network ". See ~/bin/nmapEx1.sh
for examples. Nmap can also be used to find open ports
on all hosts found on the nework OR it can attempt to find out the
type of OS running on each host.
9:42
Netcat (or nc) is also useful. It allows simple network comms
between two hosts using the command line. At the
server: netcat -l -p 5000
#blocks on a tcp socket The
client netcat serverIPname
5000 Hit enter and anything you type if send over
the socket and displayed at the receiver. Note that
another similar tool, socat, is newer than netcat and offers more
functionality.
Jim Martin 9:51 PM
Network management interfaces: 1. ip
is the most widely supported (issue man 8 ip); 2.
nmcli (network mgr client) - is on recent ubuntu distros but might
not be on embedded linux or other distros. 3.iw is now
THE management interface for the wireless subsystem. It
replaces commands such as iwconfig, iwlist,
iwspy... IW does not work on our VM since there is
no wifi interface. But on a Linux machine with a wifi adapter,
try 'watch -n 1 "iw dev wlp2s0 station
dump". NOTE: We will be making
available a set of rasp. pi's with wifi for use by the class.