Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • 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.

...

Note
  • Within this and following sections, we have tried to make the descriptions and examples generic.

  • If you are following along as part of a scheduled training or bootcamp, where you see <project-name> replace this with the project name being used for the workshop (which changes) and <username> with your username.

  • Also, the hostname that you might see might change depending on the cluster you’re using.

  • 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.

...

Table of Contents
minLevel1
maxLevel1
outlinefalse
stylenone
typelist
printabletrue

...

Ex: Starting in the home folder what is the relative path to the Jan folder?

...

Answer:

...

...

Answer

...

arcc-t05/workshop/data/2023/Jan/

...

:

...

If you are following along as part of a scheduled training or bootcamp, please replace the <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.

Commands:

...

Expand
titleAnswer

arcc-t05/workshop/data/2023/Jan/

image-20240522-181215.pngImage Added

...

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).

Note

The next couple of parts list and briefly summarize the commands we will be covering within this section:

pwd, cd, ls, mkdir, mv, cp, rmdir and rm.

We will then follow up with examples on how to use them.

...

<command --help> 

Command

Description

pwd

Code Block
pwd: pwd [-LP]
Print the name of the current working directory.

cd

Code Block
cd: cd [-L|[-P [-e]] [-@]] [dir]
    Change the shell working directory.

ls

Code Block
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default)

mkdir

Code Block
Usage: mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.

mv

Code Block
Usage: mv [OPTION]... [-T] SOURCE DEST
  or:  mv [OPTION]... SOURCE... DIRECTORY
  or:  mv [OPTION]... -t DIRECTORY SOURCE...
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY

...

mkdir: Create the DIRECTORY(ies), if they do not already exist

Info

Navigating to you /home and make a folder called folder01.

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

mkdir: cannot create directory ‘folder01’: File 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/<username>/folder01
Info

If a folder already exists, you can not make it again.

...

mkdir: Create the DIRECTORY(ies), if they do not already existmkdir: Create the DIRECTORY(ies), if they do not already exist

Info

Within folder01, try creating two new folders called folder02 and folder03.

Navigate into folder02 and print the current working directory.

Code Block
[folder01]$ mkdir folder02 folder03
[folder01]$ ls
folder02 folder03
[folder01]$ cd folder02/
[folder02]$ pwd
/home/<username>/folder01/folder02
[folder02]$ cd ../..
[~]$ pwd
/home/<username>
Info

Notice: You can create multiple folders at the same time.

...

mv: Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORYs) 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 myfil.txt

Code Block
[]$ $ cd
# Create an empty file.
[~]$ touch myfil.txt
[~]$ ls
Desktop  Documents  Downloads  folder01  myfil.txt
# Rename the file ‘myfil.txt’ to ‘myfile.txt’:
Info

Move this file from myfil.txt to myfile.txt.

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’

myfile.txt into 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 ls to see what is in a relative folder.

...

cp: Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY

...

to DIRECTORY

Info

Navigate back home and create a file called myfile02.txt.

Code Block
[]$ cd
[~]$ touch myfile02.txt
[~]$ ls
Desktop  Documents  Downloads  folder01  myfile02.txt

# Copy 
Info

Copy (duplicate)

this file to a

new file

.

called myfile02b.txt.

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 myfile02b.txt into the existing folder02 folder.

Code Block
[~]$ cp myfile02b.txt folder01/
[~]$ ls folder01/
folder02  folder02folder03  myfile02b.txt  myfile.txt

...

cp: folders

Info

Navigate home and try copying the folder01 folder.

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 rmdir command can only be used to remove an empty directory.

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 rmdir to remove a directory that has files still within it. The folder must be empty.

...

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 rm command.

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: rm myfile*

The * character 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

Info

The history command allows you to look back at the last commands you’ve called.

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’
Info

You can repeat a command. Lets repeat the command labelled 223:

Code Block
[<username>@blog1 ~]$ !223
ls
Desktop  Documents  Downloads

...

Exercises: Navigation

Info

Questions:

  1. How can you return to your home folder?

  2. What command do you use if you’ve forgotten where you are in the folder hierarchy?

  3. How can you list what is in a folder as well as any subfolders?

  4. Go back through the command related slides are try for yourself.

...

Note

Only user <arcc-usernameusername> can read/write this file. No one else, not even anyone within the <project-name> group, can view this file.

...

Exercises:

...

Permissions

Info

Questions: In all cases be able to justify your answer.

  1. Can you create a folder under /project/<project-name>/username>/?

  2. Can you /project/<project-name>/intro_to_linux/ and view workshop_all.txt?

  3. Can you /project/<project-name>/intro_to_linux/ and view workshop_me.txt?

  4. Can you cd into the /opt folder?

  5. Can you cd into the /root folder?

...

Expand
titleAnswer
Code Block
[<username>]$ cd /root
-bash: cd: /root: Permission denied
[<username>]$ ls -l /
...
# No permission set for other read permissions
dr-xr-x---.   17 root root  4096 Oct  4 12: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

...

...