...
Panel |
---|
panelIconId | 1f642 |
---|
panelIcon | :slight_smile: |
---|
panelIconText | 🙂 |
---|
bgColor | #FFEBE6 |
---|
|
If you are following along as part of a scheduled training or bootcamp, please replace the arccanetrain <project-name> 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. |
...
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 ~ “tilda” character represents your home directory. |
Info |
---|
Use the pwd to confirm your current working directory, which after the above command will be home. |
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 opt folder. |
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 /usr/include/asm folder. |
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 |
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 |
...
Code Block |
---|
$ cd
[~]$ ls
Desktop Documents Downloads
[~]$ mkdir folder01
[~]$ ls
Desktop Documents Downloads folder01
[~]$ mkdir folder01
mkdir: cannot create directory ‘folder01’: File exists
[~]$ cd folder01/
[folder01]$ pwd
/home/arcc-t05<username>/folder01 |
Info |
---|
If a folder already exists, you can not make it again. |
...
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<username> |
...
mv: Rename SOURCE to DEST, or move SOURCE(s) to 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" |
...
rm: WARNING
From the command-line there is NO trash bin.!
Using rm
/rmdir
is FINAL!
...
history
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<username>@blog1 ~]$ !223
ls
Desktop Documents Downloads |
...
Exercises
Info |
---|
Questions: How can you return to your home folder? What command do you use if you’ve forgotten where you are in the folder hierarchy? How can you list what is in a folder as well as any subfolders? Go back through the command related slides are try for yourself.
|
...
Answers
Info |
---|
1: How can you return to your home folder? |
Info |
---|
2: What command do you use if you’ve forgotten where you are in the folder hierarchy? |
Info |
---|
3: How can you list what is a folder as well as any subfolders? |
Expand |
---|
|
Code Block |
---|
[]$ man ls
-R, --recursive
list subdirectories recursively
[]$ ls -R |
|
...
File Ownership and Permissions
Info |
---|
What does the output of ls –l mean? |
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 <project-name> 4096 Oct 6 08:09 ..
drwxrwsr-x 2 salexan5<someuser> arccanetrain<project-name> 4096 Oct 5 11:19 clusters
drwxrwsr-x 6 salexan5<someuser> arccanetrain<project-name> 4096 Oct 5 14:56 data
-rw-rw-r-- 1 salexan5<someuser> arccanetrain<project-name> 874 Oct 5 15:30 fruits.txt
-rw-rw-r-- 1 salexan5<someuser> arccanetrain<project-name> 34472 Oct 5 10:57 software.csv
-rw-rw-r-- 1 salexan5<someuser> arccanetrain<project-name> 1603 Oct 6 08:08 vegatables.txt
-rw-rw-r-- 1 arcc<someuser> <project-t05name> arccanetrain 26 Oct 5 07:20 workshop_all.txt
-rw------- 1 <someuser> arcc<project-t05name> arccanetrain 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> arcc<project-t05name> arccanetrain 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.
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
<project-name>
is the group.
All 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.
...
Info |
---|
This demonstrates how permissions work. Bare in mind this assumes you’re logged in as user arcc-t05 <username> . |
Code Block |
---|
[]$ cd /project/arccanetrain<project-name>/
[]$ ls -al
...
# drwxr-sr-x 2 arcc<username> <project-t01name> arccanetrain 4096 May 16 16:26 arcc-t01<username>
... |
Info |
---|
The middle set of permissions is “drwxr-sr-x” means no one other than arcc-t01 <username> has permission to write within this folder. Try navigating into a <different-username> folder within <project-name> and creating a file. |
Code Block |
---|
[arccanetrain<project-name>]$ cd arcc<different-t01username>/
# Can arcc-t05<username> create (write) a file within this folder?
[arcc<different-t01username]$ touch text.txt
touch: cannot touch 'text.txt': Permission denied |
Note |
---|
No one, other than arcc<different-t01username> can create (write) a file within this folder. |
...
If we change directories, and go to /project/
...
<project-name>/intro_to_linux, what permissions do the contents of this directory have?
Code Block |
---|
[arcc-t01<username>]$ cd ../intro_to_linux
[arcc-t01<username>]$ ls -al
# -rw-rw-r-- 1 arcc<arcc-t05username> arccanetrain<project-name> 26 Oct 5 07:20 workshop_all.txt |
Info |
---|
Any user within the arccanetrain <project-name> group can read/write the file workshop_all.txt . 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> 23 Oct 5 07:20 workshop_me.txt
[intro_to_linux]$ cat workshop_me.txt
cat: workshop_me.txt: Permission denied |
Note |
---|
Only user arcc<arcc-t05usernameusername> can read/write this file. No one else, not even anyone within the arccanetrain <project-name> group, can view this file. |
...
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 |
---|
|
Code Block |
---|
[arcc-t05@blog1 ~]$ cd /opt
[arcc-t05@blog1 opt]$ |
Yes |
Info |
---|
Questions: In all cases be able to justify your answer. Can you create a folder under /project/<project-name>/username>/ ? Can you /project/<project-name>/intro_to_linux/ and view workshop_all.txt ? Can you /project/<project-name>/intro_to_linux/ and view workshop_me.txt ? Can you cd into the /opt folder? Can you cd into the /root folder?
|
...
Answers
Info |
---|
1. Can you create a folder under /project/<project-name>/username>/ ? |
Expand |
---|
|
Code Block |
---|
[]$ cd /project/<project-name>/
[<project-name>]$ cd <username>
[<username>]$ touch test.txt
# Do you get a “Permission denied”? |
Yes. You should have write permissions as owner for this folder. Code Block |
---|
# drwxr-sr-x 2 <username> <project-name> 4096 May 16 16:26 <username> |
|
Info |
---|
2. Can you /project/<project-name>/intro_to_linux/ and view workshop_all.txt ? |
Expand |
---|
|
Code Block |
---|
[<username>]$ cd ../intro_to_linux
[intro_to_linux]$ cat workshop_all.txt
# Do you get a “Permission denied”? |
Yes. Everybody can read this. Code Block |
---|
-rw-r--r-- 1 <arcc-username> <project-name> 26 Sep 4 10:38 workshop_all.txt |
|
Info |
---|
3. Can you /project/<project-name>/intro_to_linux/ and view workshop_me.txt ? |
Expand |
---|
|
Code Block |
---|
[intro_to_linux]$ cat workshop_me.txt
# Do you get a “Permission denied”? |
No. Only <arcc-username> can read/write this file. Code Block |
---|
-rw------- 1 <arcc-username> <project-name> 23 Sep 4 10:38 workshop_me.txt |
|
Info |
---|
4. Can you cd into the /opt folder? |
Expand |
---|
|
Code Block |
---|
[<username>]$ cd /opt
[<username> opt]$
# “other” has read permissions
drwxr-xr-x. 5 root root 43 Jun 26 11:47 opt |
Yes. The other has read permissions. Code Block |
---|
drwxr-xr-x. 5 root root 43 Jun 26 11:47 opt |
|
Info |
---|
5. Can you cd into the /root folder? |
Expand |
---|
|
Code Block |
---|
[arcc-t05@blog1 ~<username>]$ cd /root
-bash: cd: /root: Permission denied
[arcc-t05@blog1 ~<username>]$ ls -l /
...
# “other” has No permission set for other read permissions
drwxrdr-xr-x---. 17 5 root root 4096 Oct 43 Jun4 26 1112:47 opt
...
# No permission set for other read permissions
58 root |
No. There are no permissions set for other read permissions. Code Block |
---|
dr-xr-x---. 17 root root 4096 Oct 4 12:58 root | No |
...
Next Steps