...
What the file system is, and a typical organization / hierarchy.
Some high-level comparison to that of Windows.
Absolute vs relative paths.
Commands:
pwd
,cd
,ls
,mv
,cp
,mkdir
,rmdir
,rm
History:
history
File Ownership and Permissions.
Table of Contents | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Some high-level comparison to that of Windows
| Windows | Linux |
Structure | Uses (data) drives C:, D:, E:… | Uses a tree hierarchy starting at “ Known as the root directory. |
|
|
|
Syntax | Uses the back slash: “\” | Uses the forward slash: “/” |
Home folder |
|
|
Application Install |
|
|
Folder and Filenames | Case insensitive: FoLdEr = FOLDER | Case sensitive: FoLdEr ≠ FOLDER |
|
| Wherever you are within the hierarchy is known as your current working directory (cwd) |
Linux OS General Structure
...
Linux Hierarchical Structure: Example
...
Absolute Path: /home/arcc-t05/
Path starts with a “/”
...
Absolute Path: /home/arcc-t05/workshop/projects/p01/etc/
...
Relative Path: workshop/projects/p01/etc/
Path does not start with a “/”
...
Relative Path: p01/etc/
...
Ex: Starting at / (root), what is the absolute path to the bits folder?
...
Answer:
Expand | ||
---|---|---|
| ||
/usr/include/bits/ |
Ex: Starting in the home folder what is the relative path to the Jan folder?
...
Answer:
Expand | ||
---|---|---|
| ||
arcc-t05/workshop/data/2023/Jan/ |
Panel | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
If you are following along as part of a scheduled training or bootcamp, please replace the arccanetrain directory with the project directory you’ve been provided for your specific training/bootcamp. If you are training independently, please use your own project folder, but contact arcc-help@uwyo.edu if you would like a copy of the files and directories used in our examples. |
Commands:
...
Note |
---|
|
...
Table of Contents | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
Some high-level comparison to that of Windows
| Windows | Linux |
Structure | Uses (data) drives C:, D:, E:… | Uses a tree hierarchy starting at “ Known as the root directory. |
|
|
|
Syntax | Uses the back slash: “\” | Uses the forward slash: “/” |
Home folder |
|
|
Application Install |
|
|
Folder and Filenames | Case insensitive: FoLdEr = FOLDER | Case sensitive: FoLdEr ≠ FOLDER |
|
| Wherever you are within the hierarchy is known as your current working directory (cwd) |
...
Linux OS General Structure
...
Linux Hierarchical Structure: Example
...
Absolute Path: /home/arcc-t05/
Path starts with a “/”
...
Absolute Path: /home/arcc-t05/workshop/projects/p01/etc/
...
Relative Path: workshop/projects/p01/etc/
Path does not start with a “/”
...
Relative Path: p01/etc/
...
Ex: Starting at / (root), what is the absolute path to the bits folder?
...
Answer:
Expand | ||
---|---|---|
| ||
/usr/include/bits/ |
...
Ex: Starting in the home folder what is the relative path to the Jan folder?
...
Answer:
Expand | ||
---|---|---|
| ||
arcc-t05/workshop/data/2023/Jan/ |
...
Commands:
Info |
---|
Commands are used to perform certain operating system tasks through the Command Line Interface, as directed by the interpreter (as opposed to a Graphical Interface Interpreter we would usually use). |
<command --help>
...
Command
...
Description
...
pwd
...
Note |
---|
The next couple of parts list and briefly summarize the commands we will be covering within this section:
We will then follow up with examples on how to use them. |
...
<command --help>
Command | Description | ||
pwd |
| ||
cd |
| ||
ls |
| ||
mkdir |
| ||
mv |
|
...
<command --
...
help>: continued
Command | Description | ||
cp |
| ||
rmdir |
| ||
rm |
|
...
pwd: Print the name of the current working directory
Info |
---|
If you get lost, then you can jump back to the home folder. |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 ???]$ cd [arcc-t05@blog1<username>@blog1 ~]$ |
Info |
---|
The |
Info |
---|
Use the |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 ~]$ pwd /home/arcc-t05<username> |
...
cd: Change the shell working directory
Info |
---|
Start by navigating back to home. |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 ???]$ cd [arcc-t05@blog1<username>@blog1 ~]$ |
Info |
---|
Move up one level, into the current folder’s parent. |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 ~]$ cd .. [arcc-t05@blog1<username>@blog1 ~]$ pwd /home |
Info |
---|
Move up another level into the root folder. |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 home]$ cd .. [arcc-t05@blog1<username>@blog1 /]$ pwd / |
...
cd: Change working directory (cont)
Info |
---|
Navigate into the |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 /]$ cd opt [arcc-t05@blog1<username>@blog1 opt]$ pwd /opt |
Info |
---|
Question: Did we define an an absolute or relative path? |
...
Info |
---|
First reset back to home. |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 opt]$ cd [arcc-t05@blog1<username>@blog1 ~]$ |
Info |
---|
Navigate into the |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 ~]$ cd /usr/include/asm [arcc-t05@blog1<username>@blog1 asm]$ pwd /usr/include/asm |
...
Info |
---|
Navigate up two levels: |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 asm]$ cd ../.. [arcc-t05@blog1<username>@blog1 usr]$ pwd /usr |
Info |
---|
Navigate back home: |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 usr]$ cd [arcc-t05@blog1<username>@blog1 ~] |
...
ls: List information about the FILEs (cwd by default)
...
Info |
---|
List files in the user’s home folder. |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 ~]$ ls |
Info |
---|
List long format that includes ownership and permission details. |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 ~]$ ls -l |
Info |
---|
List all files, including hidden files and folders start with “.”. Notice how ‘short-name’ options are grouped. |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 ~]$ ls –a |
Info |
---|
List all files with long format. |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 ~]$ ls –al |
Info |
---|
List all files with long format, in reverse order. |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 ~]$ ls –alr |
Info |
---|
List all files with long format, in reverse order, in human readable form. |
Code Block |
---|
arcc-t05@blog1<username>@blog1 ~]$ ls –alrh |
Info |
---|
Note how we can use multiple options together. |
...
Code Block |
---|
# Demonstrate how to ‘ls’ to a folder outside cwd [~]$ ls /project/arccanetrain<project-name>/arcc-t01 folder01 myfile.txt |
...
mkdir: Create the DIRECTORY(ies), if they do not already exist
Info |
---|
Navigating to you |
Code Block |
---|
$ cd
[~]$ ls
Desktop Documents Downloads
[~]$ mkdir folder01
[~]$ ls
Desktop Documents Downloads folder01
|
Info |
---|
Try creating that folder again. What happens? |
Code Block |
---|
[~]$ mkdir folder01 mkdir: cannot create directory ‘folder01’: File exists exists |
Note |
---|
If a folder already exists, you can not make it again. |
Info |
---|
Navigate into this folder and print the current working directory. |
Code Block |
---|
[~]$ cd folder01/ [folder01]$ pwd /home/arcc-t05<username>/folder01 |
Info |
---|
If a folder already exists, you can not make it again. |
...
mkdir: mkdir: Create the DIRECTORY(ies), if they do not already exist
Info |
---|
Within Navigate into |
Code Block |
---|
[folder01]$ mkdir folder02 folder03 [folder01]$ ls folder02 folder03 [folder01]$ cd folder02/ [folder02]$ pwd /home/arcc-t05<username>/folder01/folder02 [folder02]$ cd ../.. [~]$ pwd /home/arcc-t05 |
...
Info |
---|
Notice: You can create multiple folders at the same time. |
...
mv: Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY
Info |
---|
Renaming a file is the same as moving it to a new name. Navigate to your home and create a file called |
Code Block |
---|
[]$ cd # Create an empty file. $ cd [~]$ touch myfil.txt [~]$ ls Desktop Documents Downloads folder01 myfil.txt # Rename the file ‘myfil.txt’ to ‘myfile.txt’: |
Info |
---|
Move this file from |
Code Block |
---|
[~]$ mv myfil.txt myfile.txt [~]$ ls Desktop Documents Downloads folder01 myfile.txt |
...
mv: Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY
Code Blockinfo |
---|
# Move the file ‘myfile.txt’ into the directory ‘folder01’ |
Code Block |
---|
[~]$ mv myfile.txt folder01/
[~]$ ls
Desktop Documents Downloads folder01
# Demonstrate how to ‘ls’ what is in a relative folder.
[~]$ ls folder01/
folder02 myfile.txt |
...
Info |
---|
Notice how we used |
...
cp: Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY
Code Blockinfo |
---|
# Navigate back to home: $ cd # Use the touch command to create an empty file.home and create a file called |
Code Block |
---|
[]$ cd [~]$ touch myfile02.txt [~]$ ls Desktop Documents Downloads folder01 myfile02.txt # Copy |
Info |
---|
Copy (duplicate) this file to a new file .called |
Code Block |
---|
[~]$ cp myfile02.txt myfile02b.txt
[~]$ ls
Desktop Documents Downloads folder01 myfile02b.txt myfile02.txt
# Copy a file into an existing folder.
|
Info |
---|
Copy file |
Code Block |
---|
[~]$ cp myfile02b.txt folder01/
[~]$ ls folder01/
folder02 folder03 myfile02b.txt myfile.txt |
...
cp: folders
Info |
---|
Navigate home and try copying the |
Code Block |
---|
[~]$ cp folder01 cp: missing destination file operand after 'folder01' Try 'cp --help' for more information. [~]$ ls folder01 folder02 myfile02b.txt myfile.txt [~]$ cp folder01 folder03folder04 cp: -r not specified; omitting directory 'folder01’ |
...
Code Block |
---|
[~]$ cp –r folder01 folder03folder04 [~]$ ls Desktop Documents Downloads folder01 folder03folder04 myfile02b.txt myfile02.txt [~]$ ls folder03folder04 folder02 myfile02b.txt myfile.txt |
...
rmdir: Remove the DIRECTORY(ies), if they are empty
Info |
---|
The |
Code Block |
---|
[~]$ ls Desktop Documents Downloads folder01 folder03folder04 myfile02b.txt myfile02.txt [~]$ mkdir folder04folder05 [~]$ ls Desktop Documents Downloads folder01 folder03folder04 folder04folder05 myfile02b.txt myfile02.txt # Can remove folder04folder05 since it is empty. [~]$ rmdir folder04folder05 [~]$ ls Desktop Documents Downloads folder01 folder03 myfile02b.txt myfile02.txt [~]$ rmdir folder03folder04/ rmdir: failed to remove 'folder03folder04/': Directory not empty |
Info |
---|
You can not use |
...
rm: Remove (unlink) the FILE(s)
Info |
---|
Look at one way at removing a folder that itself contains folders and files. |
Code Block |
---|
[~]$ cd [~]$ cd folder03folder04 [folder03folder04]$ ls folder02 myfile02b.txt myfile.txt [folder03folder04]$ ls folder02/ [folder03folder04]$ # ‘folder02’ is empty. [folder03folder04]$ rmdir folder02/ [folder03folder04]$ ls myfile02b.txt myfile.txt [folder03folder04]$ rm myfile.txt [folder03folder04]$ ls myfile02b.txt [folder03folder04]$ rm myfile02b.txt |
...
rm: Remove (unlink) the FILE(s)
Code Block |
---|
[folder03folder04]$ ls [folder03folder04]$ # ‘folder03’‘folder04’ is now empty. [folder03folder04]$ cd .. [~]$ rmdir folder03folder04/ [~]$ ls Desktop Documents Downloads folder01 myfile02b.txt myfile02.txt # This has taken a lot of individual steps. # Can we do this |
Note |
---|
This has taken a lot of individual steps. Can we do this quicker? |
...
rm: folders and file(s)
Info |
---|
Take a further look at the |
Code Block |
---|
[~]$ cd [~]$ rm folder01/ rm: cannot remove 'folder01/': Is a directory |
...
Code Block |
---|
[~]$ rm -r folder01/
[~]$ ls
Desktop Documents Downloads myfile02b.txt myfile02.txt
# Can remove multiple files.
[~]$ rm myfile02b.txt myfile02.txt
[~]$ ls
Desktop Documents Downloads
# Alternatively we could have removed above 2 files with: rm myfile*
# * is a wildcard, so the rm myfile* will remove all starting with the characters "myfile" |
Info |
---|
Alternatively we could have removed the above 2 files with: The |
...
rm: WARNING
From the command-line there is NO trash bin.!
Using rm
/rmdir
is FINAL!
...
history
Info |
---|
The |
Code Block |
---|
[~]$ history --help
history: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
Display or manipulate the history list.
...
[~]$ history
...
219 rm -f folder01/
220 rm -r folder01/
221 ls
222 rm myfile02b.txt myfile02.txt
223 ls
224 history
# Repeat command ‘223’
[arcc-t05@blog1 |
Info |
---|
You can repeat a command. Lets repeat the command labelled |
Code Block |
---|
[<username>@blog1 ~]$ !223
ls
Desktop Documents Downloads |
...
Exercises: Navigation
Info |
---|
Questions:
|
...
|
...
Answers
Info |
---|
1: How can you return to your home folder? |
Expand | ||
---|---|---|
| ||
|
Info |
---|
2: What command do you use if you’ve forgotten where you are in the folder hierarchy? |
Expand | ||
---|---|---|
| ||
|
Info |
---|
3: How can you list what is a folder as well as any subfolders? |
Expand | ||
---|---|---|
| ||
|
...
File Ownership and Permissions
Info |
---|
What does the output of |
Code Block |
---|
[arcc-t05@blog1<username>@blog1 ~]$ cd /project/arccanetrain<project-name>/intro_to_linux [arcc-t05@blog1<username>@blog1 intro_to_linux]$ ls -al total 54 drwxrwsr-x 4 salexan5<someuser> arccanetrain<project-name> 4096 Oct 6 08:09 . drwxrws--- 40 root arccanetrain 4096 Oct 6 08:09 .. drwxrwsr-x 2 salexan5 arccanetrain 4096 Oct 5 11:19 clusters drwxrwsr-x 6 salexan5 arccanetrain 4096 Oct 5 14:56 data -rw-rw-r-- 1 salexan5 arccanetrain 874 Oct 5 15:30 fruits.txt -rw-rw-r-- 1 salexan5 arccanetrain 34472 Oct 5 10:57 software.csv -rw-rw-r-- 1 salexan5 arccanetrain 1603 Oct 6 08:08 vegatables.txt -rw-rw-r-- 1 arcc-t05 arccanetrain 26 Oct 5 07:20 workshop_all.txt -rw------- 1 arcc-t05 arccanetrain 23 Oct 5 07:20 workshop_me.txt |
The first character on the left indicates if it is a directory “d” or a file “-”.
Code Block |
---|
drwxrwsr-x clusters # A folder.
-rw-rw-r-- workshop_all.txt # A file. |
File Ownership and Permissions
Code Block |
---|
-rw-rw-r . drwxrws--- 40 root <project-name> 4096 Oct 6 08:09 .. drwxrwsr-x 2 <someuser> <project-name> 4096 Oct 5 11:19 clusters drwxrwsr-x 6 <someuser> <project-name> 4096 Oct 5 14:56 data -rw-rw-r-- 1 <someuser> <project-name> 874 Oct 5 15:30 fruits.txt -rw-rw-r-- 1 <someuser> <project-name> 34472 Oct 5 10:57 software.csv -rw-rw-r-- 1 <someuser> <project-name> 1603 Oct 6 08:08 vegatables.txt -rw-rw-r-- 1 <someuser> <project-name> 26 Oct 5 07:20 workshop_all.txt -rw------- 1 <someuser> <project-name> 23 Oct 5 07:20 workshop_me.txt |
Info |
---|
The first character on the left indicates if it is a directory “d” or a file “-”. |
Code Block |
---|
drwxrwsr-x clusters # A folder.
-rw-rw-r-- workshop_all.txt # A file. |
...
File Ownership and Permissions
Code Block |
---|
-rw-rw-r-- 1 <username> <project-name> 26 Oct 5 07:20 workshop_all.txt |
...
User: This is the owner of the file/folder. By default, the person who created it becomes its owner.
<username>
is the owner
Group: A group is a collection of users. The primary purpose of the group is to define a set of privileges for a given resource that can be shared among the users within the group.
<project-name>
is the group.In general, for a workshop, all attending users / the
arcc-txx
users (if being used) have been setup to be within this group.
Other: This is any other user who has access to the file/folder. This person has neither created the file, nor do they belong to a user group.
...
Permission Denied
Info |
---|
This demonstrates how permissions work. Bare in mind this assumes you’re logged in as user |
Code Block |
---|
[]$ cd /project/<project-name>/
[]$ ls -al
...
# drwxr-sr-x 2 <username> <project-name> 4096 May 16 16:26 <username>
... |
Info |
---|
The middle set of permissions is “drwxr-sr-x” means no one other than Try navigating into a |
Code Block |
---|
[<project-name>]$ cd <different-username>/
# Can <username> create (write) a file within this folder?
[<different-username]$ touch text.txt
touch: cannot touch 'text.txt': Permission denied |
Note |
---|
No one, other than |
...
If we change directories, and go to /project/<project-name>/intro_to_linux, what permissions do the contents of this directory have?
Code Block |
---|
[<username>]$ cd ../intro_to_linux
[<username>]$ ls -al
# -rw-rw-r-- 1 <arcc-username> <project-name> 26 Oct 5 07:20 workshop_all.txt |
Info |
---|
Any user within the Everybody can read it. Do you want anyone outside of this project to be able to read this file? |
Code Block |
---|
[] ls -al # -rw------- 1 arcc<arcc-t05username> arccanetrain<project-name> 2623 Oct 5 07:20 workshop_all.txt |
...
User: This is the owner of the file/folder. By default, the person who created it becomes its owner.
arcc-t05
is the owner
Group: A group is a collection of users. The primary purpose of the group is to define a set of privileges for a given resource that can be shared among the users within the group.
arccanetrain
is the group.All the
arcc-txx
users have been setup to be within this group.
Other: This is any other user who has access to the file/folder. This person has neither created the file, nor do they belong to a user group.
Permission Denied
Info |
---|
This demonstrates how permissions work. Bare in mind this assumes you’re logged in as user arcc-t05 .me.txt
[intro_to_linux]$ cat workshop_me.txt
cat: workshop_me.txt: Permission denied |
Note |
---|
Only user |
...
Exercises: Permissions
Info |
---|
Questions: In all cases be able to justify your answer.
|
...
Answers
Info |
---|
1. Can you create a folder under |
Expand | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
| ||||||||||
Info | ||||||||||
The middle set of permissions is “drwxr-sr-x” means no one other than arcc-t01 has permission to write within
Yes. You should have write permissions as
|
Note |
---|
No one, other than |
...
|
Info |
---|
2. Can you |
...
Code Block |
---|
[arcc-t01
|
Expand | |||
---|---|---|---|
| |||
|
Info |
---|
Any user within the Everybody can read it. Do you want anyone outside of this project to be able to read this file? |
Code Block | |||
---|---|---|---|
[] ls -al
# -rw------- 1 arcc-t05 arccanetrain 23 Oct 5 07:20 workshop_me.txt
Yes. Everybody can read this.
|
Info |
---|
3. Can you |
Expand | ||
---|---|---|
| ||
|
Note |
---|
Only user |
Exercise: Try it
Code Block |
---|
[]$ cd /project/arccanetrain/
[arccanetrain]$ cd arcc-t05
[arcc-t05]$ touch test.txt
# Do you get a “Permission denied”?
# Navigate into the intro_to_linux folder.
[arcc-t05]$ cd ../intro_to_linux
[intro_to_linux]$ cat workshop_all.txt
Everybody can read this.
[intro_to_linux]$ cat workshop_me.txt
# Do you get a “Permission denied”?
# Can you cd into the /opt folder?
# Justify your answer.
# Can you cd into the /root folder?
# Justify your answer. |
Answers
Can you cd into the /opt
folder?
Expand | ||
---|---|---|
| ||
Yes |
No. Only
|
Info |
---|
4. Can you |
Expand | ||||
---|---|---|---|---|
| ||||
Yes. The
|
Info |
---|
5. Can you |
Expand | ||||
---|---|---|---|---|
| ||||
No. There are no permissions set for
No |
...
...
Previous | Workshop Home | Next |