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

task-optimization-slides

The document provides an overview of various UNIX command-line operations, including file management, input/output redirection, and file permissions. It covers essential commands such as 'chmod', 'cp', 'mv', and tools like 'sed' and 'awk' for text processing. Additionally, it discusses user management and special file permissions, along with the use of tar for archiving files.

Uploaded by

akym
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

task-optimization-slides

The document provides an overview of various UNIX command-line operations, including file management, input/output redirection, and file permissions. It covers essential commands such as 'chmod', 'cp', 'mv', and tools like 'sed' and 'awk' for text processing. Additionally, it discusses user management and special file permissions, along with the use of tar for archiving files.

Uploaded by

akym
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Task Optimization

Mateo Prigl
SOFTWARE DEVELOPER
Demo

Brace expansion
Demo

Build commands from stdin with xargs


Demo

Checking for destructive operations


Demo

Opening files in external programs


Summary Brace expansion
Build commands with xargs
Checking for destructive operations
Opening files in external programs
Summary
UNIX Filesystem
/

/bin /etc /home /var

bash crontab /mprigl /cache


car cups /john /lib
chmod fonts /mike /lock
cp fstab /lara /log
date host.conf /opt
echo hostname ...
grep hosts
... ...
~ sign represents your home directory
Navigation in Check your current directory with pwd
Shell
Move to other directories with cd
File Types

Directories – contain other files

Regular files
Match patterns with wildcards
* matches zero or more characters

Globbing ? matches exactly one character


[A-Z] will match any letter of the alphabet
Z Shell has glob qualifiers
Use find to locate files by name
Create files with touch

Managing Create directories with mkdir

Files Remove empty directories with rmdir


Remove files with rm
Remove non-empty directories with rm –r
Command-line Text Editors

nano vi emacs
Page through the file with more and less

Reading File Read the first lines of a file with head

Contents Read the last lines of a file with tail


Count the number of lines with wc
Input/Output Redirection

stdin stdout
Command
0 1

stderr

2
Redirect standard input with <

Input/Output Redirect standard output with >

Redirection Redirect standard error with 2>


Create command pipelines with |
Pick the data from a line with cut

Processing Translate characters with tr

Lines Get unique lines with uniq


Sort lines with sort
File Permissions

Permissions File Directory

Read (r) Open and read List the contents


r

Add, remove and


Write (w) Edit (modify) contents
rename files within it

Execute
Execute (x) (executable file)
Enter inside (cd into it)
Changing Permissions
File Permissions (symbolic mode)

u user

= set permissions

g group

chmod + add permission


r w x filename
o other

- remove permission
a all
Changing Permissions
File Permissions (absolute/numeric mode)

4 2 1
r w x
1 0 0 1 --x
chmod 2 0 1 0 -w- filename
4 1 0 0 r--
1+2=3 0 1 1 -wx
Default UNIX Permissions

File Permission Directory Permission

666 777
rw-rw-rw- rwxrwxrwx
Default File Permissions

Default
6 6 6 rw-rw-rw-
permissions

Umask - 0 2 2 --- -w- -w-

6 4 4 rw- r-- r--


Create users with useradd

Managing Set the login password with passwd

Users and User information is stored in /etc/passw


Groups Create groups with addgroup
Login to other account with su - username
Special File Permissions

Permissions File Directory

Run file as a file


SUID (s or S)
r owner

Run file as a
All of the files inside of it will
SGID (s or S) member of the
belong to the directory group
file group
Prevents files inside of it from
Sticky bit (t or T) being removed by anyone but
the owner of that file
Copy files with cp

Moving Files Move and rename files with mv


Backup and synchronize files with rsync
Soft (symbolic) links only hold the filename
of a file they point to
Links
Hard links point to inodes
Processing Search for patterns with grep

Text Transform text with sed and awk


SED Workflow
$ sed ' ' file
file Terminal
Pattern space first line
first line
first line
second line Input stream Output stream
third line

Hold buffer
AWK Workflow
awk
'BEGIN {
print "execute before everything"
}
/expression/ {
print "execute on each line from the input stream"
}
END {
print "execute after everything"
}'
filename
Tar Options

Option Purpose
v Verbose output

f Use an archive file


r
c Create an archive

t List the archive content

x Extract files from an archive

z Gzip compression

j Bzip2 compression

You might also like