Computer Services & Repairs
Chicago and Suburbs
 

Table of Contents


 

5.02 Files/Directories Utilities

ls - list directory contents (shows listing, index that point to actual inodes, files)

Options:

-1 list (one)

-C columns

-F flags (File or directory)

-R Recursive (travels directory tree from the top down, and shows as well all files)

-S size

-X extension

-a all

-d directory names

-k kilobytes (needs to be combined with the -s option)

-l long (provides a long format, which includes file details with the -t, list in revere time order)

-m commas

-r reverse

-s size

-t time

-x horizontally



dirs - displays the stack

Options:

-c clears

-l long

-p preface

-v verbose



pushd - pushes a directory on the stack

dir directory name

+N number

-N nu


Example:

[bash]$ pushd mnt/floppy/bikes

[bash]$ pushd mnt/floppy/cars



popd - removes directories from the directory stack

+N number

-N number



cd - changes to another working directory (change directories)

cd alone moves you to the home directory

Dot(.) indicated current directory number

Double Dot(..) is a parent directory



pwd - print(display) working directory



mkdir - creates a directory

Options:

-p parent #creates parent and child directories

-v verbose #display steps being made



rmdir - deletes directory

Options:

-p parent

-v verbal



rm - deletes a files or directories

Options:

-d directory

-f force

-I interactive

-r, R recursively

-v verbose



mv - changes the name of a file

Options:

-f force

-u update (move only when source file is newer than the destination file, or when destination file is missing)

-i interactive

-v verbose



file - test the contents of a file

Options:

-b brief mode

-i mime (Multi Purpose Internet Extension)

-s special files

-v version of file and location of magic file

-z tries to look inside compressed files.

  • endian:refers to the ordering of bytes in a multi-byte number

  • little-endian: is an order in which the little end (least signifant value in the sequence) is stored first

  • big-endian: is in contrast to little-endian, in which the big end (most significant value in the sequence) is stored first



touch - changes file timestamps



cp - copies a file

Options:

-b backup (creates a backup file if overwritten with a ~ sign, and will preserve the attributes of the orginal file, such as permissions and the date)

-f force

-i interactive

-p preserve the attributes of the original file, such as permissions and the date)

-r, R recursively

-v verbose


Example:

[bash]$ cp *.foo1 *.foo2 foo.filedirectory


cmp - compares the contents of two files from each other. Reports the first different character found, and the line number



cat - display a text file # (does not allow to scroll, but piped ( | ) with more or less you can)

-A show all (will show even non printing characters)

-b numbers non blank output lines

-e equivalent to –vE

- E display a $ at the end of each line

-n numbers all output lines

-t equivalent to –vT

-T displays tab characters as ˆI

-v Uses the ˆ and M to show non printing characters except for line feeds and tabs


Example: How to create a file by redirection using a cat command

[bash]$cat foo*.* > foo.file #(Displayed text redirects to a foo.file)


Example: How to create simple script using a cat commands and redirection

[bash]$ cat > commands # (creates script on to go)

dd # (delete a line)

G # (go to the bottom)

p # (paste the line)

:wq # (write the file to a disk and quit)

vim foo.file < commands # (execute script on the foo.file)

Example: Using a cat - to determine which version of the OS is installed

[bash]$cat/etc/issue

 

Example: Using cat - to determine what file systems are mounted and where they are mounted

[bash]$cat/etc/mtab


Example: username:password:uid:gid:comments:homedir:shell

[bash]$cat/etc/passwd


Example: checks the fstab file for the actual name of your floppy drive, and the whereis command verified the location of fdformat and mkfs.

[bash]$cat/etc/fstab; whereis fdformat mkfs


 

more - file perusal filter for CRT viewing. Its is a filter for paging through text one screen at the time. This version is especially primitive. The command Less provides more emulation and extensive enhancements.



less - is a program similar to more, but which allows backward movement. With large files starts up faster that text editors.


Example: How to use more and less commands

[bash]$ more *.foo

#(or)

[bash]$ less *.foo

 


touch - changes file time stamp

-a changes access time

-c do not create any files ( this prevent touch from creating a file if already exists.)

-m only changes modification time



ln - creates a hard link



ln –s - creates a symbolic link to an existing file

 
 
   

Copyright 2006 © Burnnet Computers LLC.