Brief Introduction to Linux (2024)

This guide is designed for new users of the Levich Institute Linux servers who have no prior experience.

Linux file system and basic commands

Inquire system resources

Show operating system:

jmao@Jupiter:~$ cat /etc/issueUbuntu 22.04.1 LTS

Show kernel version:

jmao@Jupiter:~$ uname -aLinux Jupiter 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux


Show disk usage of mounted file systems:

jmao@Jupiter:~$ dfFilesystem 1K-blocks Used Available Use% Mounted on/dev/sdb 263174212 31208448 218527608 13% /tmpfs 6524932 0 6524932 0% /mnt/wsltools 511747028 506051256 5695772 99% /initnone 6524932 4 6524928 1% /runnone 6524932 0 6524932 0% /run/locknone 6524932 0 6524932 0% /run/shmnone 6524932 0 6524932 0% /run/usertmpfs 6524932 0 6524932 0% /sys/fs/cgroupdrivers 511747028 506051256 5695772 99% /usr/lib/wsl/driverslib 511747028 506051256 5695772 99% /usr/lib/wsl/libC:\ 511747028 506051256 5695772 99% /mnt/cD:\ 1953512444 863395912 1090116532 45% /mnt/dF:\ 5860487164 4247379760 1613107404 73% /mnt/fG:\ 104857600 99446620 5410980 95% /mnt/g

Show disk usage of mounted file systems in human readable unit:

jmao@Jupiter:~$ df -hFilesystem Size Used Avail Use% Mounted on/dev/sdb 251G 30G 209G 13% /tmpfs 6.3G 0 6.3G 0% /mnt/wsltools 489G 483G 5.5G 99% /initnone 6.3G 4.0K 6.3G 1% /runnone 6.3G 0 6.3G 0% /run/locknone 6.3G 0 6.3G 0% /run/shmnone 6.3G 0 6.3G 0% /run/usertmpfs 6.3G 0 6.3G 0% /sys/fs/cgroupdrivers 489G 483G 5.5G 99% /usr/lib/wsl/driverslib 489G 483G 5.5G 99% /usr/lib/wsl/libC:\ 489G 483G 5.5G 99% /mnt/cD:\ 1.9T 824G 1.1T 45% /mnt/dF:\ 5.5T 4.0T 1.6T 73% /mnt/fG:\ 100G 95G 5.2G 95% /mnt/g

Show disk usage of folders:

jmao@Jupiter:~$ du -hs *1.2M 1akk144K 1akk.pdb17.6M 1fue6.0M 4j8p116M 4lzt1.1M 4lzt_new25M 6nwa3.2G Downloads148K Figure_1.png4.0K LightsailDefaultKey-us-east-1.pem90M Miniconda3-latest-Linux-x86_64.sh8.0K Untitled.ipynb4.0K a32K batch-download-structures-1716948321485.zip4.0K bin4.0K chemsilo48K cve_list.json440M cves940K cyc

Show CPU and memory usage:

top

Press "q" to quit.

or

htop

Press F10 key to quit.

Show memory usage:

jmao@Jupiter:~$ free -h total used free shared buff/cache availableMem: 12Gi 66Mi 11Gi 0.0Ki 969Mi 12GiSwap: 4.0Gi 0B 4.0Gi

Show current users on the system:

who

Show recently logged in users:

last

Show user information:

finger username

Send a message to another user:
Syntax: write username [terminal]

write jmao pts/0

Use CTRL-D to end the message.

Display a command manual:

man last

Inquire current user name:

whoami


File system and related commands

List files:

Basic command: ls

jmao@Jupiter:~$ ls1akk bin java_error_in_pycharm_1372.log pcet1akk.pdb1 chemsilo java_error_in_pycharm_1425.log pcet_demo1fue cve_list.json java_error_in_pycharm_1470.log projects4j8p cves java_error_in_pycharm_1561.log pycharm4lzt cyc java_error_in_pycharm_1941.log scan.txt4lzt_new d java_error_in_pycharm_2031.log seaborn-data6nwa delphi java_error_in_pycharm_307.log testDownloads diprotic_demo java_error_in_pycharm_3624.log test.datFigure_1.png drobo java_error_in_pycharm_3687.log test.txtLightsailDefaultKey-us-east-1.pem fad java_error_in_pycharm_387.log uiucMiniconda3-latest-Linux-x86_64.sh fmn_Em_-520 java_error_in_pycharm_475.log user_paramUntitled.ipynb granepura java_error_in_pycharm_489.loga index.html josebatch-download-structures-1716948321485.zip ipscan miniconda3

Some useful options for command `ls`:

CommandFunction
ls -lList details
ls -lhlist with human readable details units
ls -alist hidden files *
ls -ltlist files in chronological order, newest first
ls -lrtlist files in chronological order, reversed order

* Under Linux, hidden files are those files names tart with a "."

Navigate file system
Go to home directory:

cd or cd ~

Go to parent directory:

cd ..

In Unix, ". ." means parent directory, "." means current directory, and "~" means user's home directory.

Go to a directory:

cd Documents

or

cd /home/jmao/Documents

The first command uses relative path and the second uses absolute path.

Show current directory's absolute path:

pwd

Look for files
To locate a file by name:

jmao@ChemE:~$ locate Documents/Users/jmao/Documents/Users/jmao/Documents/MATLAB/Users/jmao/Documents/New Document.ott/Users/jmao/Documents/New Spreadsheet.otsjmao@ChemE:~$ locate -b '\Documents'/Users/jmao/Documents

The command "locate" searches folder name and file name that contains the specified string. If you want to search the exact file name, the option "-b" limits the scope to base name (excluding path name before the match, but still printed out), and the escape "\" removes the global name match. Be noted that `locate` command searches from a database refreshes daily, therefore new files may not show up in the search.

To search a file:

jmao@ChemE:~$ find ./ -name Documents./Documents

The locate command searches a pre-updated database (usually refreshed everyday) and the find command searches the actual file system.

jmao@ChemE:~$ touch myfilejmao@ChemE:~$ locate -b '\myfile'jmao@ChemE:~$ find ~/ -name myfile/home/jmao/myfile

Find an executable

"whereis" finds the command location and the same command name may appear in multiple places. "which" finds the location of command that will be called. You can always specify the full path to call the desired command.

jmao@ChemE:~$ whereis python python: /usr/bin/python3.6 /usr/bin/python2.7 /usr/bin/python3.6m /usr/bin/python3.5m /usr/bin/python3.5 /usr/bin/python /usr/lib/python3.6 /usr/lib/python2.7 /usr/lib/python3.5 /usr/lib/python3.7 /etc/python3.6 /etc/python2.7 /etc/python3.5 /etc/python /usr/local/lib/python3.6 /usr/local/lib/python2.7 /usr/local/lib/python3.5 /usr/include/python2.7 /usr/include/python3.6m /usr/share/python /Users/jmao/miniconda3/bin/python /Users/jmao/miniconda3/bin/python3.6m-config /Users/jmao/miniconda3/bin/python3.6m /Users/jmao/miniconda3/bin/python3.6-config /Users/jmao/miniconda3/bin/python3.6 /usr/share/man/man1/python.1.gz jmao@ChemE:~$ which python /home/jmao/miniconda3/bin/python

Find current directory:

pwd


Unix file permissions

If you list files in details, you see some strings like this:

jmao@ChemE:~$ ls -ltotal 84drwxr-xr-x 2 jmao jmao 4096 Feb 7 14:35 Desktop-rwxrwxr-x 1 jmao jmao 45 Jan 25 07:21 test3.py-rw-r--r-- 1 jmao jmao 87 Jan 25 07:49 test.pydrwxr-xr-x 2 jmao jmao 4096 Mar 27 2018 Videosd: directoryr: read permissionw: write permissionx:execute permission

The first character is reserved for directory. Other 9 characters are divided into three rwx fields. They are for owner, group, and others. The permission bits control how these files are read, wriitten, and determine if they can be run as a program.

To change permission, use

chmod

command.

Word mode of chmod command

One way to edit the file permission bits is through the word mode. Example:

chmod a+w file

In above example, "a" is reference, "+" is operator, and "w" is mode. It means, all three permission fields turn on write permission. Other references, operators and modes are:

ReferenceMeaning
uUser (Owner)
gGroup
oOthers
aAll, same as "ugo"
OperatorMeaning
+Turn on
-Turn off
=Set to be
ModeMeaning
rReadable
wWritable
xExecutable, or allow to enter when being adirectory

Example:

"chmod a+x file" turns a file to be executable by all users.

"chmod go-rwx file" makes a file not accessible by group and other users.

Binary mode of command chmod

Alternatively, you can set a file permission with a binary string.

rwx fields can be viewed as a binary number. When set, the value is 1, otherwise is 0. For example, rw_rw_rw is 110,110,110 in binary, and 666 in octal. So

chmod 666 file

means to set file to permission ```rw_rw_rw```.

This is a very straight forward way to set permission.

Handle files

Here are some commonly used commands to handle files:

CommandExampleMeaning
cpcp file file.bakcopy file to file.bak
cp -r run01 run02recursicely copy directory run01 to directory run02
cp -a file1 file2copy file and preserve file properties (permission, time etc)
rmrm filedelete file
rm -rf folderrecursively and silently delete directory named folder
mvmv file1 file2rename (move) file1 to file2
filefile filenamedetermine file type, text or binary or compressed, etc
catcat text_fileprint text file contents
lessless text_filenavigate text file content, "q" to exit
moremore text-filesame as "less" command
mkdirmkdir dirnamemake a directory
rmdirrmdir dirnamedelete an empty directory, see "rm -rf"
touchtouch fileupdate file time stamp or create an empty file
wcwc -l text_filecount number of lines


Special commands

There are some commands to handle odd situations in a terminal, for example, a terminal may hang, or print unrecognizable characters. These command may help.

CTRL-D

Send an EOF signal to the terminal. Some commands like mail and talk let you type text in terminal as input, but needs a non-text to indicate the end of input. This key combination indicates the end of file (text).

If you press this key combination at the terminal prompt, it serves as log out command.

CTRL-C

Interrupt a command, not resumable. Example:

jmao@ChemE:~$ sleep 60^C

CTRL-Z

Interrupt a command, resumable with "fg" at foreground or "bg" at background.

jmao@jmao-desktop ~/projects/mcce-develop $ sleep 120 ^Z[1]+ Stopped sleep 120jmao@jmao-desktop ~/projects/mcce-develop $ fgsleep 120

&

Send a job to background. Background job runs at background and you have the control of terminal before command finishes.

sleep 10sleep 10 &"jobs"

Check jobs issued from this terminal.

CTRL-L or "clear"


Clear the termical window.

"reset"

Reset and clear terminal. In case you ran some program and turned your terminal unusable, type in reset may give you back the terminal.

"history"

Show command history of this terminal window.

"echo $?"

$? is a special environment variable, holding the return value of the previous command. Each command has an exit code. Normally 0 means successful exit.

Brief Introduction to Linux (2024)
Top Articles
Craigslist Eugene Oregon
Craigslist Albany Oregon Free Stuff
2016 Hyundai Sonata Refrigerant Capacity
Administrative Supplement Program to Add Fluid-based Biomarkers and APOE Genotyping to NINDS ADRD Human Subjects Research Grants
El Paso Craigs
Sallisaw Bin Store
Cloud Cannabis Grand Rapids Downtown Dispensary Reviews
Weather On October 15
Conan Foal
What to Do For Dog Upset Stomach
16Th Or 16Nd
Florida death row inmates promised more humane treatment after lawsuit settlement
Barefoot Rentals Key Largo
Crestwood Funeral Home Obituaries Gadsden Al
Pathfinder 2E Throwing Weapons
These Mowers Passed the Test and They’re Ready To Trim Your Lawn
Lynette Mettey Feet
Staples Ups Drop Off
Stephjc Forum
Joy Ride 2023 Showtimes Near Amc Ward Parkway
Ixl Spring Branch
Interview With Marc Rheinard (Team ToniSport & Awesomatix) From Germany
Magicseaweed Capitola
Chess Unblocked Games 66
Blue Beetle Showtimes Near Regal Independence Plaza & Rpx
Uscis Fort Myers 3850 Colonial Blvd
Acb Message Board Yahoo
Www.statefarm
Baby | Voeding | Voeding het eerste jaar; borstvoeding
The Origins Behind Kurt Angle's "Perc Angle" Nickname In TNA
6 Beste EN Nuud Kortingscode | Tot 55% korting | September 2024
7148646793
Wall Street Journal Currency Exchange Rates Historical
Sweeterthanolives
Grave Digger Wynncraft
Auto Next, 2496 Mount Moriah Rd, Memphis, TN 38115, US - MapQuest
Mario Party Superstars Rom
Walgreens Wellington Green
The Top 6 Most Expensive Hermès Birkin Bags
Mathlanguage Artsrecommendationsskill Plansawards
Investeerder Parry bijt bij Vitesse van zich af: 'Mensen willen mij beschadigen'
Leo 2023 Showtimes Near Amc Merchants Crossing 16
Amariah Morales Snapchat
The Penitent One Unmasked
Meggen Nut
Craigslist Pelham Al
Doctor Strange in the Multiverse of Madness - Wikiquote
Bitlife Tyrone's
Craigslist Cars By Owner
Bòlèt New York Soir
Lubbock Avalanche Journal Newspaper Obituaries
Pike County Buy Sale And Trade
Latest Posts
Article information

Author: Velia Krajcik

Last Updated:

Views: 5787

Rating: 4.3 / 5 (74 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Velia Krajcik

Birthday: 1996-07-27

Address: 520 Balistreri Mount, South Armand, OR 60528

Phone: +466880739437

Job: Future Retail Associate

Hobby: Polo, Scouting, Worldbuilding, Cosplaying, Photography, Rowing, Nordic skating

Introduction: My name is Velia Krajcik, I am a handsome, clean, lucky, gleaming, magnificent, proud, glorious person who loves writing and wants to share my knowledge and understanding with you.