old-www/LDP/GNU-Linux-Tools-Summary/html/x3289.htm

1700 lines
24 KiB
HTML

<HTML
><HEAD
><TITLE
>Working with files and folders</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="GNU/Linux Command-Line Tools Summary"
HREF="book1.htm"><LINK
REL="UP"
TITLE="Working with the file-system"
HREF="c2690.htm"><LINK
REL="PREVIOUS"
TITLE="Working with the file-system"
HREF="c2690.htm"><LINK
REL="NEXT"
TITLE="Mass Rename/copy/link Tools"
HREF="x4055.htm"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>GNU/Linux Command-Line Tools Summary</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="c2690.htm"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 7. Working with the file-system</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x4055.htm"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="WORKING-FILES-FOLDERS"
></A
>Working with files and folders</H1
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>mkdir</DT
><DD
><P
><A
NAME="AEN3296"
></A
>Make a directory. Use<SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
> mkdir -p<A
NAME="AEN3299"
></A
></I
></SPAN
> to create subdirectories <A
NAME="AEN3301"
></A
>automatically.<A
NAME="AEN3303"
></A
></P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Directories are Folders: </B
>Directories are sometimes called folders in other operating systems (such as Microsoft Windows)</P
></BLOCKQUOTE
></DIV
><P
>Examples:</P
><PRE
CLASS="SCREEN"
>mkdir -p /home/matt/work/maths</PRE
><P
>This would create the directories <A
NAME="AEN3311"
></A
>&ldquo;work&rdquo; and &ldquo;maths&rdquo; under matt's home <A
NAME="AEN3313"
></A
>directory (if matt's home <A
NAME="AEN3315"
></A
>directory <A
NAME="AEN3317"
></A
>didn't exist <A
NAME="AEN3319"
></A
>it would create that too).</P
><PRE
CLASS="SCREEN"
>mkdir foo</PRE
><P
>This would create a directory in the current path <A
NAME="AEN3323"
></A
>named &ldquo;foo&rdquo;.</P
></DD
><DT
>rm</DT
><DD
><P
><A
NAME="AEN3329"
></A
>Remove/delete<A
NAME="AEN3331"
></A
><A
NAME="AEN3333"
></A
> a file(s) or directories(s). You can use standard wildcards <A
NAME="AEN3335"
></A
>with this command <A
HREF="x11655.htm#STANDARD-WILDCARDS"
>the Section called <I
>Standard Wildcards (globbing patterns)</I
> in Chapter 20</A
>.</P
><P
>Command syntax:</P
><PRE
CLASS="SCREEN"
>rm -options file_or_folder</PRE
><P
>You can of course use standard wildcards to delete multiple files or multiple<A
NAME="AEN3341"
></A
> directories <A
NAME="AEN3343"
></A
>and files.</P
><P
>Use the<SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
> -R<A
NAME="AEN3347"
></A
></I
></SPAN
> or <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>-r<A
NAME="AEN3350"
></A
></I
></SPAN
> option to remove <A
NAME="AEN3352"
></A
>recursively, this removes <A
NAME="AEN3354"
></A
>everything <A
NAME="AEN3356"
></A
>within subdirectories.<A
NAME="AEN3358"
></A
> Also try the <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>-f<A
NAME="AEN3361"
></A
></I
></SPAN
> option to force <A
NAME="AEN3363"
></A
>removal (useful when you don't want to be prompted).</P
><DIV
CLASS="TIP"
><BLOCKQUOTE
CLASS="TIP"
><P
><B
>Disabling Aliases (per execution): </B
>On some systems such as <SPAN
CLASS="PRODUCTNAME"
>Mandrake</SPAN
> an alias will send <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>rm</I
></SPAN
> to <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>rm -i<A
NAME="AEN3371"
></A
></I
></SPAN
> (prompting you for every file you wish to delete). To override this use: <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>\rm -R directory </I
></SPAN
>(using the \ disables the alias for this run only)</P
></BLOCKQUOTE
></DIV
></DD
><DT
>rmdir</DT
><DD
><P
><A
NAME="AEN3378"
></A
>Remove an empty <A
NAME="AEN3380"
></A
>directory. If you want to remove <A
NAME="AEN3382"
></A
>a directory with files in it type &ldquo; rm -R directory&rdquo;, read above for information <A
NAME="AEN3384"
></A
>on<SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
> rm -R</I
></SPAN
></P
><P
>Command syntax:</P
><PRE
CLASS="SCREEN"
>rmdir directory</PRE
><P
>This will only remove <A
NAME="AEN3390"
></A
>directory if it's empty <A
NAME="AEN3392"
></A
>otherwise it will exit <A
NAME="AEN3394"
></A
>with an error <A
NAME="AEN3396"
></A
>message.</P
></DD
><DT
>mv</DT
><DD
><P
><A
NAME="AEN3402"
></A
>Move a file or a directory to a new <A
NAME="AEN3404"
></A
>location or rename <A
NAME="AEN3406"
></A
>a file/directory.</P
><P
>Rename <A
NAME="AEN3409"
></A
>example: </P
><PRE
CLASS="SCREEN"
>mv filename1 filename2</PRE
><P
>Renames <A
NAME="AEN3413"
></A
>filename1 <A
NAME="AEN3415"
></A
>to filename2.<A
NAME="AEN3417"
></A
></P
><P
>To move <A
NAME="AEN3420"
></A
>a file or directory, simply type: </P
><PRE
CLASS="SCREEN"
>mv original_file_or_folder new_location</PRE
><P
>Note that this command can use standard wildcards <A
NAME="AEN3424"
></A
><A
HREF="x11655.htm#STANDARD-WILDCARDS"
>the Section called <I
>Standard Wildcards (globbing patterns)</I
> in Chapter 20</A
> to move <A
NAME="AEN3427"
></A
>files (not for renaming).</P
><DIV
CLASS="TIP"
><BLOCKQUOTE
CLASS="TIP"
><P
><B
>Move and rename: </B
>Note that you can also move and rename a file in a single command. The difference is with the destination (right hand side) you change the filename to the new name of the file.</P
><P
>For example typing:</P
><PRE
CLASS="SCREEN"
>mv /etc/configuration.txt /home/joe/backupconfig</PRE
><P
>This would move the file &quot;configuration.txt&quot; to /home/joe/ and rename it &quot;backupconfig&quot;</P
></BLOCKQUOTE
></DIV
></DD
><DT
>cp</DT
><DD
><P
><A
NAME="AEN3439"
></A
>Copy a file. Has a number <A
NAME="AEN3441"
></A
>of useful options, such as<SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
> -R <A
NAME="AEN3444"
></A
></I
></SPAN
>(or <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>-r</I
></SPAN
>) which <A
NAME="AEN3447"
></A
>recursively <A
NAME="AEN3449"
></A
>copies <A
NAME="AEN3451"
></A
>directories and subdirectories.<A
NAME="AEN3453"
></A
></P
><P
>Command syntax:</P
><PRE
CLASS="SCREEN"
>cp -options file_or_files new_location</PRE
><P
>Examples:</P
><PRE
CLASS="SCREEN"
>cp file1 file2</PRE
><P
>Simply copy file1 <A
NAME="AEN3460"
></A
>to file2 <A
NAME="AEN3462"
></A
>(in the same directory).</P
><PRE
CLASS="SCREEN"
>cp /tmp/file1 ~/file2 /mnt/win_c</PRE
><P
>Where the last <A
NAME="AEN3466"
></A
>option is the directory to be copied to. The above example copies <A
NAME="AEN3468"
></A
>two files from different areas of the file system to /mnt/win_c</P
><PRE
CLASS="SCREEN"
>cp -R directory_and_or_files new_location</PRE
><P
>This command will copy directories (and all subdirectories) and/or files t<SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>o new_location<A
NAME="AEN3473"
></A
></I
></SPAN
> </P
><P
>Note that this command can use standard wildcards <A
NAME="AEN3476"
></A
><A
HREF="x11655.htm#STANDARD-WILDCARDS"
>the Section called <I
>Standard Wildcards (globbing patterns)</I
> in Chapter 20</A
> to copy <A
NAME="AEN3479"
></A
>multiple files.</P
><P
>You may also like to try the &ldquo;-u&rdquo;<A
NAME="AEN3482"
></A
> when moving <A
NAME="AEN3484"
></A
>large directories <A
NAME="AEN3486"
></A
>around, this copies <A
NAME="AEN3488"
></A
>only if the source <A
NAME="AEN3490"
></A
>file is newer <A
NAME="AEN3492"
></A
>than the destination <A
NAME="AEN3494"
></A
>to where you are copying <A
NAME="AEN3496"
></A
>to, or if the destination file does not exist <A
NAME="AEN3498"
></A
>at all.</P
></DD
><DT
>ln</DT
><DD
><P
><A
NAME="AEN3504"
></A
>Create a link <A
NAME="AEN3506"
></A
>to a file. There are two types <A
NAME="AEN3508"
></A
>of links:<A
NAME="AEN3510"
></A
></P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Hard&nbsp;links</DT
><DD
><P
><A
NAME="AEN3517"
></A
>Hard links are considered pointers <A
NAME="AEN3519"
></A
>to a file (the number is listed <A
NAME="AEN3521"
></A
>by typing<SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
> ls -l</I
></SPAN
>)<SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
><A
NAME="AEN3525"
></A
></I
></SPAN
>. Each hard-link <A
NAME="AEN3527"
></A
>is a reference <A
NAME="AEN3529"
></A
>to a file.</P
><P
>The file itself only goes away when all hard-links <A
NAME="AEN3532"
></A
>are deleted.<A
NAME="AEN3534"
></A
> If you delete the original <A
NAME="AEN3536"
></A
>file and there are hard links <A
NAME="AEN3538"
></A
>to it the original file will remain. </P
><P
>Example:</P
><PRE
CLASS="SCREEN"
>ln target_name link_name </PRE
><P
>Will create a &ldquo;hard link&rdquo; to target_name <A
NAME="AEN3543"
></A
>called link_name,<A
NAME="AEN3545"
></A
> you need to delete both of these to remove<A
NAME="AEN3547"
></A
> the file.</P
></DD
><DT
>Symbolic&nbsp;links</DT
><DD
><P
><A
NAME="AEN3553"
></A
>Symbolic links are created by typing &ldquo;ln -s&rdquo;.<A
NAME="AEN3555"
></A
><SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
> </I
></SPAN
>When you remove <A
NAME="AEN3558"
></A
>the original <A
NAME="AEN3560"
></A
>file the symbolic link <A
NAME="AEN3562"
></A
>becomes broken,<A
NAME="AEN3564"
></A
> a symbolic link <A
NAME="AEN3566"
></A
>is similar to a windows <A
NAME="AEN3568"
></A
>&ldquo;short-cut&rdquo;. </P
><P
>The advantage <A
NAME="AEN3571"
></A
>of symbolic <A
NAME="AEN3573"
></A
>links is that the target can be to something on another file-system, while hard-links <A
NAME="AEN3575"
></A
>can only exist <A
NAME="AEN3577"
></A
>on the same file-system.<A
NAME="AEN3579"
></A
></P
><P
>For example:</P
><PRE
CLASS="SCREEN"
>ln -s target_name link_name</PRE
><P
>This creates a symbolic link to &ldquo;target_name&rdquo; called &ldquo;link_name&rdquo;, if you delete the original <A
NAME="AEN3584"
></A
>file the symbolic link won't work (it becomes a broken <A
NAME="AEN3586"
></A
>link).</P
></DD
></DL
></DIV
></DD
><DT
>shred</DT
><DD
><P
><A
NAME="AEN3592"
></A
>Securely remove <A
NAME="AEN3594"
></A
>a file by overwriting <A
NAME="AEN3596"
></A
>it first. Prevents <A
NAME="AEN3598"
></A
>the data <A
NAME="AEN3600"
></A
>from being recovered <A
NAME="AEN3602"
></A
>by software <A
NAME="AEN3604"
></A
>(and even by most hardware), please be very careful <A
NAME="AEN3606"
></A
>when using shred as you may never be able <A
NAME="AEN3608"
></A
>to retrieve<A
NAME="AEN3610"
></A
> the data <A
NAME="AEN3612"
></A
>you have run <A
NAME="AEN3614"
></A
>the application <A
NAME="AEN3616"
></A
>on.</P
><P
>For example:</P
><PRE
CLASS="SCREEN"
>shred -n 2 -z -v /dev/hda1</PRE
><A
NAME="AEN3620"
></A
><BLOCKQUOTE
CLASS="BLOCKQUOTE"
><P
><A
NAME="AEN3622"
></A
><A
NAME="AEN3624"
></A
><A
NAME="AEN3626"
></A
>&ldquo;What this tells shred, is to overwrite <A
NAME="AEN3628"
></A
>the partition <A
NAME="AEN3630"
></A
>2 times with random<A
NAME="AEN3632"
></A
> data <A
NAME="AEN3634"
></A
>(- n 2) then finish <A
NAME="AEN3636"
></A
>it up by writing <A
NAME="AEN3638"
></A
>over it with zeroes <A
NAME="AEN3640"
></A
>(-z) and show <A
NAME="AEN3642"
></A
>you its progress (-v). Of course, change <A
NAME="AEN3644"
></A
>/dev/hda1 to the correct partition <A
NAME="AEN3646"
></A
>. Each pass <A
NAME="AEN3648"
></A
>can take some time,<A
NAME="AEN3650"
></A
> which is why I set <A
NAME="AEN3652"
></A
>it to only do 2 random<A
NAME="AEN3654"
></A
> passes <A
NAME="AEN3656"
></A
>instead of the default <A
NAME="AEN3658"
></A
>25. You can adjust <A
NAME="AEN3660"
></A
>this number, of course, to your particular level of paranoia<A
NAME="AEN3662"
></A
> and the amount <A
NAME="AEN3664"
></A
>of time you have.</P
><P
>Since shred writes on such a low-level,<A
NAME="AEN3667"
></A
> it doesn't actually matter what kind of filesystem <A
NAME="AEN3669"
></A
>is on the partition--everything will be unrecoverable.<A
NAME="AEN3671"
></A
> Once shred is finished,<A
NAME="AEN3673"
></A
> you can shutdown the machine <A
NAME="AEN3675"
></A
>and sell <A
NAME="AEN3677"
></A
>or throw<A
NAME="AEN3679"
></A
> away the drive <A
NAME="AEN3681"
></A
>with peace <A
NAME="AEN3683"
></A
>of mind.<A
NAME="AEN3685"
></A
></P
><P
>...However, even shre dding devices <A
NAME="AEN3688"
></A
>is not always completely reliable.<A
NAME="AEN3690"
></A
> For example, most disks <A
NAME="AEN3692"
></A
>map <A
NAME="AEN3694"
></A
>out bad sectors <A
NAME="AEN3696"
></A
>invisibly to the application;<A
NAME="AEN3698"
></A
> if the bad sectors <A
NAME="AEN3700"
></A
>contain sensitive <A
NAME="AEN3702"
></A
>data,<A
NAME="AEN3704"
></A
> `shred' won't be able <A
NAME="AEN3706"
></A
>to destroy<A
NAME="AEN3708"
></A
> it. [ shred info page <A
NAME="AEN3710"
></A
>].&rdquo;<A
NAME="AEN3712"
HREF="#FTN.AEN3712"
><SPAN
CLASS="footnote"
>[1]</SPAN
></A
> </P
></BLOCKQUOTE
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Shredding files doesn't work with all filesystems: </B
>Please note that as mentioned in the shred manual page (please see the manual and preferably info pages for more information). <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>shred </I
></SPAN
>does not work correctly<SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
> </I
></SPAN
>on log-structured or journaled filesystems, such as JFS, ReiserFS, XFS, Ext3 and many other modern filesystems</P
></BLOCKQUOTE
></DIV
><DIV
CLASS="TIP"
><BLOCKQUOTE
CLASS="TIP"
><P
><B
>Alternatives to using shred: </B
>shred has its disadvantages when run on a filesystem. First of all since it has to be installed you cannot run shred on your operating systems filesystem, you also cannot use shred on a windows machine easily since you cannot install <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>shred</I
></SPAN
> on this machine.</P
><P
>You may like to try alternatives such as the DBAN project that create self-booting floppy disks that can completely erase a machines hard disk.</P
></BLOCKQUOTE
></DIV
><P
>You may also like to see how <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>chattr</I
></SPAN
> <A
NAME="AEN3727"
></A
>can assist <A
NAME="AEN3729"
></A
>you in shredding <A
NAME="AEN3731"
></A
>files once they are removed (it has similar problems <A
NAME="AEN3733"
></A
>to shred,<A
NAME="AEN3735"
></A
> only ext2 <A
NAME="AEN3737"
></A
>and ext3<A
NAME="AEN3739"
></A
> style filesystems...), please see <A
HREF="x9543.htm"
>the Section called <I
>File Permissions</I
> in Chapter 14</A
>.</P
></DD
><DT
>du</DT
><DD
><P
><A
NAME="AEN3746"
></A
>Displays information <A
NAME="AEN3748"
></A
>about file size. Use<SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
> du filename </I
></SPAN
>to display <A
NAME="AEN3751"
></A
>the size <A
NAME="AEN3753"
></A
>of a particular <A
NAME="AEN3755"
></A
>file. If you use it on directories <A
NAME="AEN3757"
></A
>it will display the information on the size of the files in the directory and each subdirectory.<A
NAME="AEN3759"
></A
> </P
><P
>Options <A
NAME="AEN3762"
></A
>for du <A
NAME="AEN3764"
></A
>(use<SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
> du -option(s)</I
></SPAN
>):</P
><P
></P
><UL
><LI
><P
><SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>-c<A
NAME="AEN3771"
></A
> </I
></SPAN
>-- this will make <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>du</I
></SPAN
> print <A
NAME="AEN3774"
></A
>a grand <A
NAME="AEN3776"
></A
>total <A
NAME="AEN3778"
></A
>after all arguments <A
NAME="AEN3780"
></A
>have being processed.<A
NAME="AEN3782"
></A
></P
></LI
><LI
><P
><SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>-s<A
NAME="AEN3787"
></A
> </I
></SPAN
>-- summarises <A
NAME="AEN3789"
></A
>for each argument <A
NAME="AEN3791"
></A
>(prints the total).</P
></LI
><LI
><P
><SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>-h<A
NAME="AEN3796"
></A
></I
></SPAN
> -- prints <A
NAME="AEN3798"
></A
>things in &ldquo; human readable<A
NAME="AEN3800"
></A
>&rdquo; mode;<A
NAME="AEN3802"
></A
> for example printing <A
NAME="AEN3804"
></A
>1M (megabyte) rather than 1,024,000 (bytes).</P
></LI
></UL
><P
>Using the <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>-hs</I
></SPAN
> options on a directory will display the total <A
NAME="AEN3808"
></A
>size of the directory <A
NAME="AEN3810"
></A
>and all subdirectories.<A
NAME="AEN3812"
></A
></P
><P
>Command syntax:</P
><PRE
CLASS="SCREEN"
>du -options file_directory_or_files</PRE
><P
>Example:</P
><PRE
CLASS="SCREEN"
>du -hs *</PRE
><P
>This command will list <A
NAME="AEN3819"
></A
>the size of all files in the current directory and it will list the size of subdirectories,<A
NAME="AEN3821"
></A
> it will list things in human-readable<A
NAME="AEN3823"
></A
> sizes <A
NAME="AEN3825"
></A
>using 1024 Kb <A
NAME="AEN3827"
></A
>is a Megabyte,<A
NAME="AEN3829"
></A
> M for megabyte,<A
NAME="AEN3831"
></A
> K for kilobyte <A
NAME="AEN3833"
></A
>etc.</P
><P
></P
></DD
><DT
>file</DT
><DD
><P
>Attempts <A
NAME="AEN3840"
></A
>to find <A
NAME="AEN3842"
></A
>out what type of file it is, for example it may say it's: binary,<A
NAME="AEN3844"
></A
> an image <A
NAME="AEN3846"
></A
>file (well it will say jpeg,<A
NAME="AEN3848"
></A
> bmp <A
NAME="AEN3850"
></A
>et cetera), ASCII<A
NAME="AEN3852"
></A
> text,<A
NAME="AEN3854"
></A
> C header <A
NAME="AEN3856"
></A
>file and many other kinds of files, it's a very useful utility.<A
NAME="AEN3858"
></A
> </P
><P
>Command syntax:</P
><PRE
CLASS="SCREEN"
>file file_name</PRE
></DD
><DT
>stat</DT
><DD
><P
><A
NAME="AEN3866"
></A
>Tells you detailed <A
NAME="AEN3868"
></A
>information <A
NAME="AEN3870"
></A
>about a file, including <A
NAME="AEN3872"
></A
>inode number creation/access date. Also has many advanced <A
NAME="AEN3874"
></A
>options and uses. </P
><P
>For simple use type:</P
><PRE
CLASS="SCREEN"
>stat file</PRE
></DD
><DT
>dd</DT
><DD
><P
><A
NAME="AEN3882"
></A
>Copies data <A
NAME="AEN3884"
></A
>on a very low <A
NAME="AEN3886"
></A
>level and can be used to create copies <A
NAME="AEN3888"
></A
>of disks<A
NAME="AEN3890"
></A
> <A
HREF="x11606.htm"
>the Section called <I
>Duplicating disks</I
> in Chapter 20</A
> and many other things (for example CD image <A
NAME="AEN3893"
></A
>files). </P
><P
><SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>dd</I
></SPAN
> can also perform <A
NAME="AEN3897"
></A
>conversions on files and vary the block <A
NAME="AEN3899"
></A
>size used when writing <A
NAME="AEN3901"
></A
>the file. </P
><P
>Command syntax, note the block <A
NAME="AEN3904"
></A
>size and count <A
NAME="AEN3906"
></A
>are optional <A
NAME="AEN3908"
></A
>and you can use files instead of devices...</P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Please note: </B
><SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>dd</I
></SPAN
> is an advanced and difficult to use command. Its also very powerful, so be careful what you do with it </P
></BLOCKQUOTE
></DIV
><P
>Command syntax:</P
><P
></P
><PRE
CLASS="SCREEN"
>dd if=/dev/xxx of=/dev/xxx bs=xxxx count=x </PRE
><DIV
CLASS="WARNING"
><P
></P
><TABLE
CLASS="WARNING"
BORDER="1"
WIDTH="90%"
><TR
><TD
ALIGN="CENTER"
><B
>Warning</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>The command <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>dd</I
></SPAN
> is used to work on a very low level. It can be used to overwrite important information such as your master-boot record or various important sections of your hard-disk. Please be careful when using it (especially when working with devices instead of files).</P
></TD
></TR
></TABLE
></DIV
></DD
><DT
>touch</DT
><DD
><P
><A
NAME="AEN3925"
></A
>This command is used to create empty <A
NAME="AEN3927"
></A
>files, simply do<SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
> touch file_name</I
></SPAN
>. It is also used to update <A
NAME="AEN3930"
></A
>the timestamps <A
NAME="AEN3932"
></A
>on files.</P
><P
><SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>touch</I
></SPAN
> can be used to change <A
NAME="AEN3936"
></A
>the time and/or date of a file:</P
><PRE
CLASS="SCREEN"
>touch -t<A
NAME="AEN3939"
></A
> 05070915 my_report.txt<A
NAME="AEN3941"
HREF="#FTN.AEN3941"
><SPAN
CLASS="footnote"
>[2]</SPAN
></A
></PRE
><P
>This command would change <A
NAME="AEN3946"
></A
>the timestamp <A
NAME="AEN3948"
></A
>on my_report.txt so that it would look <A
NAME="AEN3950"
></A
>like you created it at 9:15. The first four digits <A
NAME="AEN3952"
></A
>stand for May 7th (0507), in MM-DD (American style), and the last <A
NAME="AEN3954"
></A
>four (0915) the time,<A
NAME="AEN3956"
></A
> 9:15 in the morning.<A
NAME="AEN3958"
></A
> </P
><P
>Instead of using plain <A
NAME="AEN3961"
></A
>numbers to change <A
NAME="AEN3963"
></A
>the time, you can use options similar to that of the <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>date</I
></SPAN
> tool. For example:</P
><PRE
CLASS="SCREEN"
>touch -d '5 May 2000' some_file.txt</PRE
><P
>You can also use <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>--date=</I
></SPAN
> instead of <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>-d<A
NAME="AEN3970"
></A
><A
NAME="AEN3972"
></A
>. </I
></SPAN
>Also have a look at the date command under <A
HREF="c4268.htm#DATE-TIME-CALENDARS"
>the Section called <I
>Date/Time/Calendars</I
> in Chapter 8</A
> for examples <A
NAME="AEN3975"
></A
>on using <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>-d</I
></SPAN
> and <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>--date=</I
></SPAN
> (the syntax <A
NAME="AEN3979"
></A
>for the date <A
NAME="AEN3981"
></A
>part is exactly <A
NAME="AEN3983"
></A
>the same when using <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>-d</I
></SPAN
> or <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>--date</I
></SPAN
>).</P
></DD
><DT
>split</DT
><DD
><P
><A
NAME="AEN3991"
></A
>Splits <A
NAME="AEN3993"
></A
>files into several <A
NAME="AEN3995"
></A
>smaller <A
NAME="AEN3997"
></A
>files. </P
><P
>Use the <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>-b&nbsp;xx</I
></SPAN
> <A
NAME="AEN4001"
></A
>option <A
NAME="AEN4003"
></A
>to split <A
NAME="AEN4005"
></A
>into <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>xx</I
></SPAN
> bytes,<A
NAME="AEN4008"
></A
> also try <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>-k</I
></SPAN
> <A
NAME="AEN4011"
></A
>for kilobytes,<A
NAME="AEN4013"
></A
> and <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>-m</I
></SPAN
> <A
NAME="AEN4016"
></A
>for megabytes.<A
NAME="AEN4018"
></A
> You can use it to split text files and any other files... you can use <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>cat</I
></SPAN
> to re-combine <A
NAME="AEN4021"
></A
>the files. </P
><P
>This may be useful if you have to transfer <A
NAME="AEN4024"
></A
>something to floppy <A
NAME="AEN4026"
></A
>disks <A
NAME="AEN4028"
></A
>or you wish to divide <A
NAME="AEN4030"
></A
>text files into certain sizes.<A
NAME="AEN4032"
></A
></P
><P
>Command syntax:</P
><PRE
CLASS="SCREEN"
>split -options file</PRE
><P
>This will split <A
NAME="AEN4037"
></A
>the input <A
NAME="AEN4039"
></A
>file into 1000 lines <A
NAME="AEN4041"
></A
>of input each (thats the default...), and output <A
NAME="AEN4043"
></A
>(using the above example), with the input name file, &ldquo;fileaa&rdquo; (1st part <A
NAME="AEN4045"
></A
>of file), &ldquo;fileab&rdquo; (2nd part <A
NAME="AEN4047"
></A
>of file), &ldquo;fileac&rdquo; (3rd part <A
NAME="AEN4049"
></A
>of file) etc. until the there is no more <A
NAME="AEN4051"
></A
>of the file left to split.<A
NAME="AEN4053"
></A
></P
></DD
></DL
></DIV
></DIV
><H3
CLASS="FOOTNOTES"
>Notes</H3
><TABLE
BORDER="0"
CLASS="FOOTNOTES"
WIDTH="100%"
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.AEN3712"
HREF="x3289.htm#AEN3712"
><SPAN
CLASS="footnote"
>[1]</SPAN
></A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
>This information (as quoted) has come from the &ldquo;Please, For the Love of All That's Recoverable, Shred Your Hard Drive!&rdquo; article, number 18 in the <A
HREF="b12722.htm"
><I
>Bibliography</I
></A
></P
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.AEN3941"
HREF="x3289.htm#AEN3941"
><SPAN
CLASS="footnote"
>[2]</SPAN
></A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
>This particular command and explanation has been used (with editing) from the <SPAN
CLASS="PRODUCTNAME"
>Linux</SPAN
> Online Classroom, see [4] in the <A
HREF="b12722.htm"
><I
>Bibliography</I
></A
> for further information.</P
></TD
></TR
></TABLE
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="c2690.htm"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.htm"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x4055.htm"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Working with the file-system</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c2690.htm"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Mass Rename/copy/link Tools</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>