Download as pdf or txt
Download as pdf or txt
You are on page 1of 94

• Question 1

Erases the command line in Ubuntu


Correct Answer:
Ctrl + U
• Question 2
"Assuming ""aos"" directory is not empty, write the UNIX command that will delete the given directory."

Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match rm -r aos

Exact Match rm -r "aos"

Exact Match rm -r ""aos""

• Question 3
"The head and tail commands, allow you to view the first few or last few lines of a file
(15 lines by default)."
Correct Answer: False
• Question 4
How would you write the code that will display the current calendar month

Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match cal oct 2020

Exact Match cal

• Question 5
How to suspend current foreground process in Unix
Correct Answer:
CTRL + Z
• Question 6
Write a command that will create a file called file1.txt

Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match touch file1.txt

Exact Match >file1.txt

Exact Match > file1.txt

Exact Match cat>file1.txt

• Question 7
The usrs directory contains configuration files that the system uses when the
computer starts.
Correct Answer: False
• Question 8
Command that will allow you to move a file in another directory
Correct Answer:
mv
• Question 9
Most shells keep a list of your recently used commands and allow you to recall a
command without retyping it.
Correct Answer: True
• Question 10
"How would you display the current calendar year, were the current day is selected"
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match cal -y

• Question 11
"The less command scrolls only down, whereas more enables you to scroll down and
up."
Correct Answer: False
• Question 12
Write the UNIX comannd that will create a directory called LONGTEST
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match mkdir LONGTEST

• Question 13
It indicates EOF end of file or exit
Correct Answer:
CTRL + D
• Question 14
Command that will allow you to create another name for a file
Correct Answer:
ln
• Question 15
The rm -r command can be used to delete a directory that is not empty.
Correct Answer: True
• Question 16
"Assuming you have newfile1.txt in your home directory home/leo/, how would you
copy newfile1.txt to a directory called backup"
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match cp newfile1.txt ./backup

• Question 17
"How would you list the content of the directory called ""Project"" that will show the permission of files in UNIX"

Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match ls -l

Exact Match ls -l ./Project

Exact Match ls -l ./"Project"

Exact Match ls -l ./""Project""

Exact Match ls -l Project

Exact Match ls -l "Project"

Exact Match ls -l ""Project""

• Question 18
Creates empty file and modifies the last modified timestamp
Correct Answer:
touch
• Question 19
You can use the date command to show the system calendar.
Correct Answer: False
• Question 20
Write the command that will display the current date following the sequence day month year

Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match date +%d/%m/%y

Exact Match date '+%d/%m/%y'

• Question 21
It specify the entire file hierarchy
Correct Answer:
Absolute Path
• Question 22
UNIX/Linux systems interpret a single dot character to mean the current working
directory.
Correct Answer: True
• Question 23
How would you redirects the output of a command and appends to the file in Unix
Correct Answer:
>>
• Question 24
"How would you list the content of the directory called ""Project"" that will include hidden files in UNIX"

Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match ls -a

Exact Match ls -a ./Project

Exact Match ls -a ./"Project"

Exact Match ls -a ./""Project""

Exact Match ls -a Project

Exact Match ls -a "Project"

Exact Match ls -a ""Project""

• Question 25
"You use the ls command to display a directory's contents, including files and other
directories."
Correct Answer: True
• Question 26
It reprresent the current directory position
Correct Answer:
.
• Question 27
Command that will allow you to compare to text files in UNIX

Correct Answer:
diff
• Question 28
Write the UNIX comannd that will delete a directory called project
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match rmdir project

• Question 29
Stops screen output
Correct Answer:
CTRL + S
• Question 30
"Which among the following command line that will create files as series named f1,
f2, f4"
Correct Answer:
Both A and B
• Question 31
How would you redirects the output of a command to a file and overwrites the current
content of the file.
Correct Answer:
>
• Question 32
How would clean or clear the screen in UBUNTU
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match clear

• Question 33
The command cd source uses relative path addressing.
Correct Answer: True
• Question 34
"Assuming you have file1.txt inside project directory, how would you copy file1.txt to
the home directory "
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match cp file1.txt ../

• Question 35
Create a link file of science.txt and name it as science.link
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match ln science.txt science.link

• Question 36
"Assuming you have the following files ""fruits"" and ""prutas"", write a UNIX command
that will compare the the two files"
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match diff fruits prutas

• Question 37
It represents the route through the hierarchy that is traversed to reach the desired file
or directory
Correct Answer:
pathname
• Question 38
It reprresent the directory immediately above your current position
Correct Answer:
..
• Question 39
"In UNIX, what command should you use to rename or move a file to a different
directory"
Correct Answer:
Evaluation Method Correct Answer Case Sensitivity
Exact Match mv

• Question 40
"wc is a command in UNIX used to print newline, word, and byte counts of a file"
Correct Answer: True

Cal reports the date and time

False

Set/Display network information

Hostname

Ifconfig

Ipconfig

Uname

One of the variation of Unix was called Linux

True

Command use to displays directory using absolute path name

Pwd

A command used with absolute or relative pathnames to navigate


Cd not sure

Dos command that deletes one or more files

Del

Ls command in UBUNTU is similar to pwd in MS DOS

False

Man is the command for bringing up online help in MS DOS

False

A component of a computer’s OS, this is a user interface for access to the operating system’s services.

Command line

Shell not sure

Gui

All of the above

Clear a command line screen/window for a fresh start

True or false

Dos Command showing drive C tree

Tree

A family of multitasking, multiuser computer operating systems

Unix
1. An __________________ serves as a liason between the consumers and the resources, often
coordinating the allocation of limited resources among numerous consumers.
▪ operating system
2. Give the equivalent UNIX-LINUX command of the given DOS command: ATTRIB +h or -h
▪ mv file .file
3. _______ shell that was developed at the University of California Berkley by Bill Joy that allows
recalling and editing of previously entered commands and aliasing.
▪ C
4. ________ an operating system components that manages the operation of the computer.
▪ Kernel
5. _________ is a location for other files and subdirectories.
▪ Directory
6. Program Execution _________ the user program in memory and runs it.
▪ Loads
7. Unix Variants and its manufacturer
▪ Linus Torvalds - LINUX
▪ Sun Microsystems -SOLARIS
▪ Open Software Foundation – OSF/1
▪ Microsoft - FENIX
▪ Hewlett-Packard – HP-UX
▪ IBM - AIX
▪ Digital Equipment Compaq (DEC) – ULTRIX
8. __________ shell is similar to Korn shell, it is a command programming language and command
interpreter which supports command history, line editing, filename completion, aliasing, and job
control.
▪ POSIX
9. A __________________ is the operating system feature that manages the different computer
resources such as CPU time, memory space, file storage space, I/O devices, etc. and allocates
them to different application programs and users.
▪ resource allocator
10. ______________ (3 words) handles the way files are organized within the disk or tape. It takes
care of the creation and deletion of files for users.
▪ File system handling
11. _________ shell which is an original shell program that was developed for AT&T, provides a
UNIX system command interpreter and supports a programmable interface to develop shell
programs.
▪ Bourne
12. Common Subdirectories
▪ executables, system admin utilities, and library routines - /usr directory
▪ applications and third-party applications - /opt directory
▪ files which are pointers to device names - /dev directory
▪ system admin files (passwd file) - /etc directory
▪ user home directories Correct - /export/home directory
▪ basic operating system files - /kernel directory
▪ print spooling and mail system error messages - /var directory

13. ____________ is any directory below another directory.


▪ Subdirectory
14. Give the equivalent UNIX-LINUX command of the given DOS command: BREAK ON
▪ Trap
15. A ___________ is a group of directories that can be thought of as a separate tree structure.
▪ file system
16. Give the equivalent UNIX-LINUX command of the given DOS command: SUBST V:
C:\directory\path
▪ Mount
17. _____________ controls the execution of programs and the various I/O devices.
▪ Control program
18. ___________ shell is an enhanced Bourne shell, an additional features such as aliasing and
history and is most widely used shell and is industry standard for users.
▪ Korn
19. ________ contained in directories and subdirectories.
▪ Files
20. Give the equivalent UNIX-LINUX command of the given DOS command: pkzip
▪ tar and zip
21. UNIX-LINUX Commands and its Action
IT 2625 – QUIZZIZ 1

1. Dos command that allows to advance inside the C unit - cd


2. Dos command to go back one level – cd..
3. Command showing drive C tree - tree
4. Dos command that deletes one or more files - del
5. What line is properly formatted to navigate to the windows directory? – cd .\Windows
6. What command would you use to fix errors on a hard disk? - chkdsk /F
7. Which command clears the screen? – cls
8. How would you remove ‘myfile’ from your flash drive? – del e:\myfile
9. Which command displays the read only files in a directory? – dir /A :R
10. How do you close a command prompt window? – exit
11. To copy all of the files in a directory tree, which command would you use? – xcopy
c:\Windows e:
12. The command line window is full of output from other commands and is cluttered and hard
to read. - cls
13. You want to see a list of the commands recently executed so you can choose one to run
again – F7
14. You entered a command incorrectly and would like to bring back the incorrect command so
you can correct it and run it. – up-arrow
15. You want to see all the commands available at the command line. – help
16. You are finished working at the command line and want to end the session. – exit
17. A command is generating a lot of output and is taking too long to run. You want to stop it. –
Ctrl + C
18. The basic command for creating a new directory is? – mkdir
19. The basic Linux command to delete empty directories is? – rmdir
20. The command for bringing up online help is? – man
21. To move a directory on DOS is a function of the command? – cd
22. Which of the following commands in Linux is used to display information about files and
directories contained within the current working directory? – ls
23. Which of the Linux command-line commands listed below is used for directory traversal? –
cd
24. A Linux command displaying an absolute path to (ie. full filename of) the current working
directory is called – pwd
IT 2625 – QUIZZIZ 1

25. A Linux command-line command allowing a user to change his/her own password is known
as – passwd
26. What is Terminal? – a program which enables you to access the shell
27. A command line command in Linux used for deleting files and directories is known as - rm
28. Which of the following commands allows for moving one level up in Linux directory tree? –
cd ..
29. Which of the following key combinations allows to terminate the current process in Linux
shell? – Ctrl + C
30. Which of the following commands in Linux is used to display information about files and
directories contained within the current working directory? - ls
What is an Operating System?

An Operating System is a special computer program (software) that


controls the computer (hardware). The Operating system serves as a liaison
between the consumers and the resources, often coordinating the
allocation of limited resources among numerous consumers.

Disks
Users
Memory
CPU
Operating System
Programs Network
Printers

Consumers Resources
UNIX Operating System
An operating System can be thought of as
1. Resource Allocator – the operating system manages the
different computer resources such as CPU time,
memory space, file storage space, I/O devices, etc. and
allocates them to different application programs and
users.
2. Control Program – it controls the execution of programs
and the various I/O devices.
Unix Services
An operating system provides the following services for users:
1. Program Execution – loads the user program in memory and
runs it.
2. I/O Operations – responsible for reading and/or writing data
from I/O devices such as disks, tapes, printers, keyboards, etc.
3. File System Handling – handles the way files are organized
within the disk or tape. It takes care of the creation and
deletion of files for users.
4. Error Detection – detect errors within the computer system
(CPU, memory, I/O, or user program) and take the appropriate
action.
History of UNIX
1969 UNIX developed by AT&T Bell Labs
1980 UC Berkeley BSD UNIX 4.2 becomes widely used
Early 1980s Hewlett-Packard introduces HP-UX
Early 1990s POSIX, Portable Operating System Interface
UNIX Variants
•AIX – from IBM
•HP-UX – from Hewlett-Packard
•Ultrix – from DEC
•Xenix – from Microsoft
•OSF/1 – from Open Software Foundation
•Solaris – from Sun Microsystems
•Linux – Linus Torvalds
•Ubuntu
•Suse (Novell Netware)
•Red Hat
•Debian
UNIX Varieties and Benefits

Benefits of UNIX
•based on an open standard
•supported on a wide variety of computers
•TCP/IP tightly integrated
•true 64bit architecture
•Hierarchical File System
•Multi-tasking; Multi-user
File System Directory Hierarchy
File System - group of directories that
can be thought of as a separate tree
structure
similar to logical partitions in the
Windows/DOS world (like C: or D:
drive)
made available (mounted) or
unavailable (unmounted) at the
administrator’s discretion
can either be local (on your computer)
or remote (on another computer)
Directory - location for other files and
subdirectories
like a file drawer in a file cabinet
Subdirectory - Any directory below
another directory
Files - contained in directories and
subdirectories
Common Subdirectories /usr directory - executables,
system admin utilities, and library
routines
/opt (optional) directory -
applications and third party
applications
/dev (devices) directory - files
which are pointers to device names
/etc (etcetera) directory - system
admin files (passwd file)
/export/home directory - user
home directories
/kernel directory - basic operating
system files (main UNIX kernel
genunix)
/var (variable) directory - print
spooling and mail system error
messages
Operating System Components
Shells
Bourne shell ($)
•developed by Stephen Bourne for AT&T
•original shell program
•Provides a UNIX system command interpreter
•Supports a programmable interface to develop shell programs
Korn shell ($)
•developed by David Korn at Bell Labs
•An enhanced Bourne shell
•added features such as aliasing and history
•most widely used shell and is industry standard for users
•this course is based primarily on the Korn shell
Shell cont..

C shell (%)
•developed at the University of California Berkley by Bill Joy
•Short California Shell
•based on the C programming language
•Allows recalling and editing of previously entered commands and
aliasing
POSIX shell
•Similar to Korn shell
•Command programming language and command interpreter
•It supporst command history, line editing, file name completion,
aliasing, and job control
Chapter 2
Logging In and General Orientation
Login ID and Password
Login ID
•user’s “public name”
•must be unique and limited to eight lower case letters and numbers
•stored in the password (/etc/passwd) file which can be viewed by all users
•encrypted passwords are stored in the /etc/shadow file

Passwords
•no less than six and no more than eight characters
•different from the Login ID
•at least two alphabetic characters and one numeric or special character
•case sensitive
•new password must differ by at least three characters
•may contain spaces and special characters
•these password rules do not apply to the root account!
User Accounts
Root or "super user"
•system admin
•set up by default during the installation process
•owns all system files and has access to all files
•used to create new users, manage file systems, install software and
perform other high-level system admin tasks
•Most sysadmins have a regular user account and only login as root when
necessary to perform administrative tasks

Regular User
•created and maintained by the sysadmin when logged on as root
•can run applications programs and customize working environment
•can also create and modify files in their home directory
Changing Password

•must be done at command line


•can be done by regular user
$ passwd
passwd: Changing password for user02
Enter login password: ABC 123
New password: abc 456
Re-enter new passwd: abc 456
Command-line Format
Syntax:
$ command [-options] [arguments] return
Examples:
$ date
$ls
•case sensitive
•Can type 2 commands on a single command
line, separated by a semicolon $ ls;pwd
The Secondary Prompt
$ banner ‘hi

➢there’
$(

$ if
*press ctrl c if you want to terminate currently running
program
Some Beginning Commands
$who – is used to determine the users currently
logged in the system.
$finger – same as who
$whoami – is used to determine who is currently
logged-in at a particular terminal.
$date - reports the date and time
$passwd - assign a login password
Some Beginning Commands cont.
• $echo - writes arguments to the terminal
• $clear - clears the terminal screen
• $write - sends message to username if logged in
• $talk -
• $mesg [y|n] - allows or denies writes to your terminal
Some Useful Keys to Remember
• Ctrl+C – Use this to abort a running UNIX program
• Ctrl+S – Use this freeze a screen output
• Ctrl+Q – Use this to unfreeze a screen output
• Ctrl+R – Use this to refresh or redraw your screen
• Ctrl+L – Use this if Ctrl+R does not work
• Backspace – Use this to erase mistakes before pressing the Enter key
Logging out
• Ctrl+D
• exit
man pages

UNIX Programmer’s Manual


describes the system’s on-line commands, system
calls, file formats, and system maintenance
installed by default
character-based screen displays and are not graphical
command prompt to access
man command

$ man name - help on particular command


$man -k keyword - Searches the man pages table of contents for
the specified keyword and displays one-line summary for each entry
$ man -s section name - Displays a particular section of the man
pages which can include multiple commands
Chapter 3
Getting Help
man Page Output NAME - name of command
and other commands that do
the same thing
SYNOPSIS - syntax of
command with options and
arguments
DESCRIPTION - overview of
what command does
OPERANDS - target of the
command
OPTIONS - switches that
change the function or effect of
the command; normally
preceded by a dash (-)
SEE ALSO - Refers you to
other related commands and
subjects
whatis Command

display the header line


from the manual section
brief definition of the
command
helpful if you can
remember the
command name but
forgot what it does
man Pages Scrolling

man pages can be many screens of output


Troubleshooting
Unresponsive Terminal:
•Enable screen scroll using Control –Q (Ctrl + q keys)
•Interrupt the process using Control –C (Ctrl + c keys)
•Enter EOF (end of file) using Control –D (Ctrl + d keys)
•Quit the window and restart a new one.

Unresponsive Application:
•Determine the process ID number associated with the
application and kill that process (chap 13)
•Logout and log back in again then restart the application .
Chapter 4
Accessing Files and Directories
Path Names
• A path name represents the route through the hierarchy that is
traversed to reach the desired file or directory
Types of Pathnames
Absolute Pathname
•Specifies the entire file hierarchy
•Start at root (/) and list each directory along the path to the
destination
•Slash (/) between each directory name in the path
•Example:
/home/user3/f1

Relative Pathname
•Always starts at your current location in the hierarchy
•If a pathname does not begin with a slash, it is a relative
pathname
•you must know what directory you are currently in since that is
your starting point
Absolute Path
Absolute Path
• Absolute pathname to the user2 directory
• /home/user2
• Absolute pathname to the dir1 directory
• /home/user2/dir1
• Absolute pathname to the coffees directory
• /home/user2/dir1/coffees
Relative Path
Relative Path
• If your current directory is /home:

• Relative pathname to the user2 directory


• user2
• Relative pathname to the dir1 directory
• user2/dir1
• Relative pathname to the coffees directory
• user2/dir1/coffees
Some Special Directories
Absolute Relative to
/home/user3

/home ..
/home/user2 ../user2
/home/user1/f1
../user1/f1
/ ../..

The entry called dot(.) represents your current directory position

•The entry called dot dot(..) represents the directory immediately


above your current directory position
Examples of DOT
If you are currently in the directory /home/user3:

.
./f1
./memo/f1
Examples of dot dot
• If you are currently in the directory /home:

• ..
• ../..
• ../tmp
• ../tmp/f1
• If you are currently in the directory /home/user3:

• ..
• ../..
• ../user2../user1/f1
• ../../tmp/f1
Using Navigation Shortcuts
pwd (print working directory) command -
•no options or arguments
•displays directory using absolute path name

cd (change directory) command -


•used with absolute or relative pathnames to navigate
•by itself takes you to your home directory

cd .. command takes you up one level


cd ~/ command takes you to a directory under your
home directory (tilde = home)
cd- Change Directory
Syntax:
cd [dir-pathname]
Examples:
$ pwd
/home/user3
$ cd memo; pwd
/home/user3/memo
$ cd .. /..; pwd
Using ls Command
ls
(list) listing of files and directories within the current directory or specified directories

ls –a
list all files in a directory, including hidden (.) files and current (.) and parent (..)
directories

ls –F
displays listing with a symbol to tell what the type the file is:
directory – A forward slash (/) after the name
ASCII Text File - no symbol
Executable – asterisk (*) after the name
Symbolic Link – An at sign (@)
Displaying Long Listing
Recursive Listing

ls -R (recursive) command
- Displays the contents of all directories, subdirectories and their contents for a particular part of
the directory tree
- If done at a high level in the directory structure, the output can be substantial!
Creating & Removing Files & Directories
mkdir - creates directories or folders
must have the appropriate permissions to create a directory
–p (parent) option creates parent directories while creating lower level directories, including all
the directories in a pathname

rm - removes a single file or multiple files


specify their names or use wildcard metacharacters (*) (?)
files that are deleted are permanent and cannot be recovered!
rm -i (interactive) - prompts the user before removing files
rm –r (recursive) - removes directories
removes the directory including all subdirectories and files in it!
rm -ri (or rm -ir) - removes directories interactively
mkdir and rmdir – create and remove directories

Syntax: mkdir [-p] dir_pathname (s)


rmdir dir_pathname (s)…
Example:
$ pwd
$ mkdir fruit
$ mkdir fruit/apple
$ cd fruit
$ mkdir grape orange
$ rmdir orange
$ cd ..
$ rmdir fruit
$ rmdir fruit/apple fruit/grape fruit
DOS COMMANDS
And its LINUX/UNIX Equivalent
DOS Commands and UNIX/LINUX Command (Bash or Sudo Command)
Command Comparison:
DOS Command UNIX or Bash Command Action
DIR ls -l (or use ls -lF)(-a all files)
(df -k Space remaining on List directory contents
filesystem)
DIR *.* /o-d List directory contents by reverse
DIR *.* /v /os ls -tr time of modification/creation.
DIR /s ls -ls List files and size
DIR /aa ls -R List directory/sub-directory
ls -a contents recursively.
List hidden files.
TREE ls -R List directory recursively
CD cd Change directory
DOS Command UNIX or Bash Command Action
MKDIR
mkdir Make a new directory
MD
ASSIGN ln Create a file or directory link
RMDIR
rmdir Remove a directory
RD
CHDIR pwd Display directory location
DEL
rm -iv Remove a file
ERASE
DOS Command UNIX or Bash Command Action
RMDIR /S (NT) Remove all directories and files
rm -R
DELTREE (Win 95...) below given directory
COPY cp -piv Copy a file
Copy all file of directory
XCOPY cp -R
recursivly
RENAME or MOVE mv -iv Rename/move a file
Dump contents of a file to users
TYPE cat
screen
Pipe output a single page at a
MORE more
time
HELP or COMMAND /? man Online manuals
clear
CLS Clear screen
ctrl-l
DOS Command UNIX or Bash Command Action
EXIT exit Exit a shell
EXIT0 exit 0
FIND Look for a word in files given in
grep
FINDSTR command line
Compare two files and show
COMP diff differences. Also see comm, cmp,
mgdiff and tkdiff.
Compare two files and show
FC diff differences. Also see comm, cmp,
mgdiff and tkdiff.
SET set and env List all environment variables
SET variable=value set Set environment variables
echo %variable% export variable=value Show environment variables
echo $variable
DOS Command UNIX or Bash Command Action
ECHO text echo text Echo text to screen
setenv (for C shell) or
SET variable export VAR=val (for Korn shell. Set environment variables
Also VAR=val)
Display search path for
PATH echo $PATH
executables.
PATH %PATH%;C:\DIR PATH=$PATH:/dir
Set PATH environment variable.
PROMPT $p$g export PS1='\h(\u)\W> ' Set user command prompt.
Show date. (also set date - DOS
DATE or TIME date
only)
DOSKEY /h history List command history
DOS Command UNIX or Bash Command Action
BREAK ON trap Trap ctrl-break / Trap signals.
Sort data
SORT sort
alphabetically/numerically
EDLIN ed Line mode editor
EDIT filename.txt Edit a file. The Linux editor which
looks most like DOS edit is
pico, gnp, vi, xedit, xemacs,dtpad
probably Pico. (Not a
recomendation!)
BACKUP files A:\ tar -cvf /dev/fd0 files
Save files to floppy.
mdir, mcopy
See Using DOS floppies
doswrite -a file (AIX only)
tar -xvf /dev/fd0 files
Read files from floppy.
RESTORE A:\ files mdir, mcopy
See Using DOS floppies
dosread -a file (AIX only)
DOS Command UNIX or Bash Command Action
Change file permissions. DOS:
ATTRIB [+r|-r] [+a|-a] [+s|-s]
chmod +:set to -:remove r:Read only
[path\file] /s
a:Archive s:System /s:recursively
Change file to a hidden file -
ATTRIB +h or -h mv file .file
rename file with prefix "."
PRINT lpr Print a file
CALL source script (cshrc)
Execute script from within batch
COMMAND /C (DOS), CMD (NT) . script (bash)
shell.
sh script
MEM free
Show free memory on system
top
DOS Command UNIX or Bash Command Action
SCANDISK fsck
Check and repair hard drive file system
DEFRAG C: debugfs
CHDISK du -s Disk usage.
FDISK fdisk Tool to partition a hard drive.
SUBST V: Mount a drive letter to a folder/directory on your
mount
C:\directory\path hard drive.
FORMAT mke2fs Format drive file system.
See: fdformat and mformat For floppy drive use see YoLinux Tutorial Using
for floppies DOS Floppies with Linux
uname -a
VER echo $SHELL Operating system/shell version
cat /etc/issue
pkzip Compress and uncompress files/directories. Use
tar and zip tar to create compilation of a directory before
compressing. Linux also has compress, gzip
HOSTNAME hostname Print host name of computer
PING ping Send packets to a network host
Show routes and router hops to
TRACERT traceroute
given network destination.
ifconfig
IPCONFIG (NT) Display/configure network
or
WINIPCFG (Win 95...) interface
ip addr show
Chapter 5
Basic Directory and File Management
Command Line Control Characters
What can we do with files?
ls -look at the characteristics of a file
cat -look at the contents of a file
more -look at the contents of a file, one screenful at a time
lp -print a file
cp -make a copy of a file
mv -change the name of a file or directory
mv -move a file to another directory
ln -create another name for a file
rm -remove a file
cat more head tail Commands
head
•displays the first n lines
•first 10 lines are displayed by default if the -n
option is omitted.

tail
•displays the last n lines of a file
•last 10 lines are displayed by default if the -n
option is omitted.
•allows you to check the end result of the backup
without looking at the whole file
•-n option allows you to start displaying lines from a
specific point in a file
wc and diff Commands
wc (word count) command
•displays line, word, byte or character counts for a text file
•without options will give a line, word, and byte count of the contents of the file
Option Function
-l Counts lines
-w Counts words
-c Counts bytes
-m Counts characters

diff (difference) command compares two text files and finds differences
Command Format: $ diff [option] file1 file2
–i option ignores the case of the letters
–c option performs a detailed comparison and produces a listing of differences with three lines of
context
Copy Files
• Syntax:
• cp [-i] file1 new_file
• cp [-i] file [file…] dest_dir
• cp –r [-i] dir [dir…] dest_dir

• Examples:
• $ ls –F
• $ cp f1 f1.copy
• $ ls –F
• $ cp note remind memo
Move or Rename Files
• Syntax:
• mv [-i] file1 new_file
• mv [-i] file [file…] dest_dir
• mv [-i] dir [dir…] dest_dir
• Examples:
• ls –F
• mv f1 file1
• ls –F
• mv f2 memo/file2
• ls –F
• ls –F memo
diff Output
Link Files
Syntax:
ln file new_file
ln file [file. . .] dest_dir
Example:
$ ls –l f1
$ ln f1 /home/user2/f1.link
$ ls –l f1
$ ls –l /home/user2
$ ls –i /home/user2/f1.link
Chapter 6
File System Security
Filename Specifications
•Maximum of 14 characters
•Maximum of 255 characters if long
filenames are supported
•May contain alphabetic, numeric, dot,
dash and underscore
Security Policies
•The UNIX system incorporates a 3-tier structure to define who has
access to each file and directory:
User Group Others
•The ls –l command displays the owner and group who has access to
the file
•Default for Files
Read/Write for User and read only for Group and Other
•Default for directories
Read/Write/Execute for User and Read/Execute for Group and Other
File Types
•- regular file
•d directory
•l symbolically linked file
•n network special file
•c character device file
•b block device file (disks)
File System Permissions

- rw-r-- r--
drwxr-xr-x
user - owner / creator of file or directory
group – permissions used by members of the group that owns the file or directory
other – all users other than the file owner, and members of the group that owns
the file or the directory.
Permissions
User & Group ID

$ ls -n
displays the UID and the GID
$ id
displays numeric and alphabetic User ID and Group ID for your Effective User ID (EUID)
$ groups
displays all of the groups you are a member of
Changing Permissions Syntax
$ chmod mode filename
We use the chmod command to change the access mode of a file

The mode portion is made up of three parts:


Who - Category you are working with
u = user
g = group
o = others
a = all

Op - Operator
set (=)
remove (-)
give (+)

Permission(s) assigned – Read (r), Write (w) or Execute (x)


Changing Permissions - Symbolic
Permissions - Octal Mode
octal - eight possible numbers in group
bits are either on (1) or off (0)
7 r w x 1 1 1
6 r w - 1 1 0
5 r - x 1 0 1
4 r - - 1 0 0
3 - w x 0 1 1
2 - w - 0 1 0
1 - - x 0 0 1
0 - - - 0 0 0
Changing Permissions - Octal
umask  The umask (UNIX shorthand for "user file-creation mode mask") is a
four-digit octal number that UNIX uses to determine the file
permission for newly created files
 The umask specifies the permissions you do not want given by default
to newly created files and directories. umask works by doing a bitwise
AND with the bitwise complement of the umask. Bits that are set in the
umask correspond to permissions that are not automatically assigned
to newly created files.
 By default, most UNIX variants specify an octal mode of 666 (any user
can read or write the file) when they create new files. Likewise, new
programs are created with a mode of 777 (any user can read, write, or
execute the program)
 Octal umasks are calculated via the bitwise AND of the unary
complement of the argument (using bitwise NOT) and the permissions
specified by the program: typically 666 in the case of files, and 777 in
the case of directories.
Octal umask example
• Assuming the umask has the value 174, any new file will be
created with the permissions 602 and any new directory will
have permissions 603 because:

• 666 AND NOT(174) = 602


• while
• 777 AND NOT(174) = 603

• Computation:
• 7778 = (111 111 111)2
• 1748 = (001 111 100)2
• NOT(001 111 100)2 = (110 000 011)2
• (111 111 111)2 AND (110 000 011)2 = (110 000 011)2
• 7778 NOT (174)8 (603)8
Other commands
touch - either creates one or more files with zero bytes if
none exists; or updates date/time stamp if file already exists
-a time change access time to time
-m time change modify time to time
-t time use time as your current time
-c if the file does not already exists, do not create it

Example: To create/update more than 1 file:


$touch f1.txt f2.txt f3.txt
The chgrp Command
• Changes access to a file; only the owner of file can
change the group of the file

• Syntax:
• $ chgrp newgroup filename
su - switch user id
• Changes your user id and group id designation

• Syntax:
• $ su [username]
The newgrp command
• Changes the group id.

• Syntax:
• $ newgrp [group_name]
chown
Change file ownership
Syntax:

$ chown owner [:group] filename . . .


Example:
$ id
$ cp f1 /tmp/user2/f1
$ ls -l /tmp/user2/f1
$ chown user2 /tmp/user2/f1
$ ls -l f1 /tmp/user2/f1

You might also like