0% found this document useful (0 votes)
63 views

ULI101 Week 2 Lecture Notes

This document provides an overview of key concepts in Unix/Linux file systems and commands. It describes the basic directory structure with / as the root directory and directories like home, var, etc. It explains file permissions and types. Common file system commands covered are pwd, cd, ls, mkdir, rmdir, mv, cp, rm, and touch. It also discusses using man pages, text editing, file utilities, and finding files.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

ULI101 Week 2 Lecture Notes

This document provides an overview of key concepts in Unix/Linux file systems and commands. It describes the basic directory structure with / as the root directory and directories like home, var, etc. It explains file permissions and types. Common file system commands covered are pwd, cd, ls, mkdir, rmdir, mv, cp, rm, and touch. It also discusses using man pages, text editing, file utilities, and finding files.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ULI101 – Introduction to Unix/Linux – Week 2 lecture notes

- Unix file system


- File types and file naming
- Basic file system commands: pwd, cd, ls, mkdir, rmdir, mv, cp, rm
- Man pages
- Text editing
- Common file utilities

File system is a system that allows to organize data and files in directories and subdirectories.

There is a single file structure (single root directory) in Unix/Linux, instead of having separate structures
for each drive.

Top of the file system: root (/)

~ = home directory of the current user

Command argument separator (space = special character)

cd /

ls –l = files that start with a D means they are directories

Boot directory contains all of the files necessary to start the OS (boot loader swr, kernel images, etc.)

Dev is short for devices – this directory contains file names that represent our devices – they`re not the
devices themselves, nor device drives.

Tty = component connections

Sda = hard drive partition

Etc directory contains all the system config files.

Home directory contains all the default directories for a user. Every user in the system should have a
directory in their home dir with his username. Ex: /home/vfogaca-tonioli

Every system has a superuser account (admin) – The name of the superuser account is called root

The user root also gets a home directory – it’s the only home dir not under “home”.

It’s located directly under the / directory.

The tmp directory contains temporary files that are created during PC use. Some systems periodically
clean this directory.

The usr directory is the destination of where all the software is installed.
The var directory (variable data) is where system data is stored, such as our log files, access logs, security
logs, error logs, system logs, webserver logs, print queues, website by default would be under var.

The bin directory (binaries) – binaries means that it’s an executable file. It’s where the system stores the
commands. Not everything in bin is necessary a file (could also be a script).

The sbin directory is similar to bin, except they’re different commands in different places. These are
special commands for the system administrator. Typically only accessed by the user “root”.

The default behavior of the cd command (without any arguments) is to take you to ~

The first character on a file list specifies what kind of file it is:

Starts with d = directory

Starts with - = regular file

Starts with l = symbolic link

Starts with c (dev directory) = character stream device (keyboards, etc.)

Starts with b (dev directory) = block read-write devices (storage devices)

Devices read and write streams of characters (keyboard) or blocks of characters (storage devices).

Read (R), write (W) and execute (X) permissions are listed on the 9 characters separated in 3 sets (LS
command)

When a file is created, by default its owned by somebody. (Third field ls –l tells whos the owner).

First 3 sets of permissions is assigned to the owner

Second set is assigned to the group.

Third set is assigned to “others”.

Ls –l fields: permissions / link / user / group / file size / timestamp / file name

Any filename or dir that starts with a dot will be hidden.

Ls –a (display all, hidden and non-hidden).

Every dir on the system gets an entry called dot (.)

. = this directory

Every dir except / gets an entry called dot-dot (..)

.. = the directory above me

ls –A can also be used like –a , the only difference is that . and .. don’t show up.

Combined options can be written in two ways: separate and together

ls –l –a or ls –la
ls –d displays info about the dir itself instead of the files within it

mkdir is used to create a directory (accepts options and allows multiple directories to be created at the
same time)

There’s an option for mkdir called –p. Creates any missing parent directories.

Mkdir –p dir1/dir2

OR also

Mkdir dir1 dir1/dir2

rmdir is used to remove an EMPTY directory. If there is a user, it also will not allow deletion.

rm is used to delete a file.

rm –r delete a directory AND its contents.

rm –I = asks for permission to delete.

mv is used to move something from a dir to another AND is also used to rename files/dirs.

mv dir1 dir2 – the last argument is always the destination.

If the last argument is not an existing directory, it RENAMES the origin directory.

Mv is potentially destructive because it can override preexisting data.

Ex: if I try to move dir1 into dir2, but there’s already a directory called dir1 into dir2, it’s gonna override
the preexisting directory in dir2.

mv –i = prompt the user if it’s gonna do something destructive (by default it’s off).

cp is used to copy files but can also copy dir w/ contents.

cp –r (copy recursively) – copy directory and its contents.

cp file1 dir1 (existing dir) – copies file to dir1 and keeps its name

cp file1 dir1/file2 – copies file to dir1 and renames it to file2.

touch is used to create files.

If the file already exists, it updates the timestamp (w/o modifying anything).

To put something inside quotation marks DISABLES special characters


Ex: touch “my new file” rather than touch my new file.

A backslash \ disables the meaning of the next special character

My\ new\ file or my\\file

cat command is used to view the contents of a file. (Reads content and writes it on the screen)

more command is used to view and scroll through the content of a file.

less is a better paginator than more. You can use the arrow keys to scroll the contents.

In shell, filename extensions are largely meaningless. It may be used as an indicator.

file command is used to know what type of file it is.

find command allows searching for files by file name, size and file attributes throughout the file system.

First argument: what dir do I start searching?

find /

Criteria for the search:

-name (filename)

-user (all files belonging to that user)

-mmin modified less/more than X minutes ago (-5)

-size find small/large files (100M)

man –k calendar (looks for keywords, in case you forgot a command’s name)

man –k calendar will show

cal (1)

You might also like