Il filesystem può essere “navigato” immaginando di avere una posizione variabile rispetto ad esso, solidale con la working directory. Infatti si usano espressioni del genere “Vai nella directory ...”, “Entra nella directory ...”, “In che directory sei?”, ... riferendosi semplicemente alla working directory.
In ogni directory sono sempre presenti le directory ‘.’ e ‘..’ che rappresentano rispettivamente la directory stessa e la directory padre. È inoltre possibile che in una directory siano presenti alcuni file o directory il cui nome inizia con il carattere ‘.’. Tali nomi di file e directory vengono generalmente omessi quando viene visualizzato il contenuto della directory, vengono cioè considerati come nascosti, anche se c’è comunque la possibilità di forzarne la visualizzazione.
La working directory, cioè la directory corrente, è quella che viene utilizzata per default da vari comandi di cui un esempio può essere ls (man page ls(1)) (list) che visualizza l’elenco dei file (e directory) contenuti in una directory.
____________________________________________________________________
SINTASSI
$ ls [option] [path]
DESCRIZIONE
![]()
|
![]()
|
![]()
|
mode hl user group size date_time name
dove
tuuugggooo
dove
![]()
|
![]()
|
![]()
|
total blocks
dove blocks indica il numero di blocchi del filesystem occupati dagli oggetti
elencati.
________________________________________________________________________
I colori con i quali sono visualizzati i file, sono impostati nella variabile di ambiente LS_COLORS. In genere tale variabile viene impostata con il comando dircolors (man page dircolors(1)).
__________________________________________________________________________________________________________
Comando: dircolors
Path: /usr/bin/dircolors
SINTASSI
$ dircolors [option] [filename]
DESCRIZIONE
Generalmente i file che contengono le impostazioni dei colori della visualizzazione dei file sono /etc/DIR_COLORS, a livello di sistema, e ~/.dir_colors, a livello utente (v. man page dir_colors(5)). Questi sono file di testo che contengono delle direttive costituite da righe con la seguente sintassi
[da completare ...]
I colori sono specificati secondo i codici ISO 6429 (ANSI) supportati dalla maggior parte dei terminali attuali. Tali codici sono composti da sequenze di numeri (v. tab. 4.22) separati dal carattere ‘;’.
![]()
|
NORMAL 0 Normal (non-filename) text
FILE 0 Regular file
DIR 32 Directory
LINK 36 Symbolic link
FIFO 31 Named pipe (FIFO)
SOCK 33 Socket
BLK 44;37 Block device
CHR 44;37 Character device
EXEC 35 Executable file
ORPHAN Orphanned symbolic link (non definito)
MISSING Missing file (non definito)
Nel caso si abbia a che fare con un terminale che utilizza un altro insieme di codici è
necessario utilizzare le definizioni LEFTCODE, RIGHTCODE e ENDCODE. L’output generato da ls è
composto dalla sequenza
LEFTCODE typecode RIGHTCODE filename ENDCODE
dove typecode è la sequenza numerica che specifica il colore del file filename. Se ENDCODE non
è definito, viene utilizzata la sequenza LEFTCODE NORMAL RIGHTCODE. Per default vengono
utilizzate le seguenti definizioni
LEFTCODE 0
RIGHTCODE 0
ENDCODE (non definito)
Di seguito è riportato un esempio del file /etc/DIR_COLORS.
# Configuration file for the color ls utility # This file goes in the /etc directory, and must be world readable. # You can copy this file to .dir_colors in your $HOME directory to override # the system defaults. # COLOR needs one of these arguments: 'tty' colorizes output to ttys, but not # pipes. 'all' adds color characters to all output. 'none' shuts colorization # off. COLOR tty # Extra command line options for ls go here. # Basically these ones are: # -F = show '/' for dirs, '*' for executables, etc. # -T 0 = don't trust tab spacing when formatting ls output. OPTIONS -F -T 0 # Below, there should be one TERM entry for each termtype that is colorizable TERM linux TERM console TERM con132x25 TERM con132x30 TERM con132x43 TERM con132x60 TERM con80x25 TERM con80x28 TERM con80x30 TERM con80x43 TERM con80x50 TERM con80x60 TERM cons25 TERM xterm TERM rxvt TERM xterm-color TERM color-xterm TERM vt100 TERM dtterm TERM color_xterm TERM ansi TERM screen # EIGHTBIT, followed by '1' for on, '0' for off. (8-bit output) EIGHTBIT 1 # Below are the color init strings for the basic file types. A color init # string consists of one or more of the following numeric codes: # Attribute codes: # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed # Text color codes: # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white # Background color codes: # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white NORMAL 00 # global default, although everything should be something. FILE 00 # normal file DIR 01;34 # directory LINK 01;36 # symbolic link FIFO 40;33 # pipe SOCK 01;35 # socket BLK 40;33;01 # block device driver CHR 40;33;01 # character device driver ORPHAN 01;05;37;41 # orphaned symlinks MISSING 01;05;37;41 # ... and the files they point to # This is for files with execute permission: EXEC 01;32 # List any file extensions like '.gz' or '.tar' that you would like ls # to colorize below. Put the extension, a space, and the color init string. # (and any comments you want to add after a '#') .cmd 01;32 # executables (bright green) .exe 01;32 .com 01;32 .btm 01;32 .bat 01;32 .sh 01;32 .csh 01;32 .tar 01;31 # archives or compressed (bright red) .tgz 01;31 .arj 01;31 .taz 01;31 .lzh 01;31 .zip 01;31 .z 01;31 .Z 01;31 .gz 01;31 .bz2 01;31 .bz 01;31 .tz 01;31 .rpm 01;31 .cpio 01;31 .jpg 01;35 # image formats .gif 01;35 .bmp 01;35 .xbm 01;35 .xpm 01;35 .png 01;35 .tif 01;35
Di seguito sono riportati alcuni esempi di utilizzo di ls.
[daniele@Zeus ~]$ ls /
bin documents initrd misc proc sbin TotemPrj
boot etc lib mnt public tftpboot usr
dev home lost+found opt root tmp var
[daniele@Zeus ~]$ _
[daniele@Zeus ~]$ ls -l /etc
total 2820
[...]
drwxr-xr-x 4 root root 4096 May 13 2003 gnome
drwxr-xr-x 3 root root 4096 May 13 2003 gnome-vfs-2.0
-rw-r--r-- 1 root root 9167 Feb 4 2003 gnome-vfs-mime-magic
-rw-r--r-- 1 root root 1756 Jan 29 2003 gpm-root.conf
-rw-r--r-- 1 root root 694 May 13 2003 group
-rw------- 1 root root 682 Nov 15 2002 group-
-rw------- 1 root root 5 May 13 2003 group.lock
lrwxrwxrwx 1 root root 22 Nov 15 2002 grub.conf -> ../boot/grub/grub.conf
-r-------- 1 root root 575 May 13 2003 gshadow
-rw------- 1 root root 565 Nov 15 2002 gshadow-
-rw------- 1 root root 5 May 13 2003 gshadow.lock
drwxr-xr-x 2 root root 4096 May 13 2003 gtk
drwxr-xr-x 2 root root 4096 May 13 2003 gtk-2.0
-rw-r--r-- 1 root root 17 Jul 23 2000 host.conf
-rw-r--r-- 2 root root 179 Oct 23 00:04 hosts
-rw-r--r-- 1 root root 161 Jan 13 2000 hosts.allow
-rw-r--r-- 1 root root 179 Oct 4 01:14 hosts.bak
-rw-r--r-- 1 root root 5 Feb 4 2003 hosts.canna
-rw-r--r-- 1 root root 347 Jan 13 2000 hosts.deny
drwxr-xr-x 4 root root 4096 May 13 2003 hotplug
-rw-r--r-- 1 root root 8510 Jan 26 2003 htdig.conf
drwxr-xr-x 4 root root 4096 Nov 29 19:32 httpd
-rw-r--r-- 1 root root 3376 Jan 24 2003 im_palette.pal
-rw-r--r-- 1 root root 920 Jan 24 2003 im_palette-small.pal
-rw-r--r-- 1 root root 224 Jan 24 2003 im_palette-tiny.pal
-rw-r--r-- 1 root root 5464 Jan 24 2003 imrc
-rw-r--r-- 1 root root 1247 Nov 14 2002 info-dir.rpmsave
lrwxrwxrwx 1 root root 11 May 13 2003 init.d -> rc.d/init.d
-rw-r--r-- 1 root root 658 Mar 13 2003 initlog.conf
-rw-r--r-- 1 root root 1756 Nov 15 2002 inittab
[...]
[daniele@Zeus ~]$ _
[daniele@Zeus ~]$ ls -l /dev/hda{,1,2,3,4}
brw-rw---- 1 root disk 3, 0 Jan 30 2003 /dev/hda
brw-rw---- 1 root disk 3, 1 Jan 30 2003 /dev/hda1
brw-rw---- 1 root disk 3, 2 Jan 30 2003 /dev/hda2
brw-rw---- 1 root disk 3, 3 Jan 30 2003 /dev/hda3
brw-rw---- 1 root disk 3, 4 Jan 30 2003 /dev/hda4
[daniele@Zeus ~]$ _
[da completare ...]
La working directory, che per default è quella contenuta nella variabile di ambiente HOME, può essere visualizzata con il comando pwd (print working directory). Generalmente la shell ha un comando interno pwd e le relative informazioni sono ottenibili con il comando help pwd come descritto nel cap. 3.
____________________________________________________________________
SINTASSI
$ pwd [-L|-P]
DESCRIZIONE
[daniele@Zeus ~]$ pwd
dà il seguente risultato
/home/daniele
ovvero indica il fatto che la working directory è attualmente impostata alla home directory
dell’utente identificato dallo username “daniele”.
La working directory può essere variata per mezzo del comando cd (change directory), anch’esso un comando interno della shell.
____________________________________________________________________
SINTASSI
$ cd [-L|-P] [dir]
DESCRIZIONE