If you can see this check that

next section prev section up prev page next page

Using the * wildcard characters with mv, cp, and rm

Wildcard characters are often useful when you want to move or copy multiple files from one directory to another. For example, suppose you have two directories immediately below your current directory, named 'new' and 'old', and these directories contain the following files:

% ls new
myfile myfile2
% ls old
myfile3 myfile4

To move all the files from the directory 'new' into the directory 'old', we would type:

% mv new/* old
% ls new             ( no files in new)
% ls old             ( all files are now in old)
myfile myfile2 myfile3 myfile4

We can do a similar operation with the cp command. For example, to copy all the files from old into new, we could type:

% cp old/* new

Similarly, we can use wildcard characters with the rm command. For example, to remove all of the files in the directory new, type:

% rm new/*
% ls new             ( all the files are now gone )

Warning: be careful when using wildcard that you do not accidentally remove or move files that you need.


Centos 7 intro: Paths | BasicShell | Search
Linux tutorials: intro1 intro2 wildcard permission pipe vi essential admin net SELinux1 SELinux2 fwall DNS diag Apache1 Apache2 log Mail
Caine 10.0: Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Mock Exam |
Caine 13.0: Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Registry | Mock Exam |
CPD: Cygwin | Paths | Files and head/tail | Find and regex | Sort | Log Analysis
Kali: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7a | 8a | 8b | 9 | 10 |
Kali 2020-4: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7 | 8a | 8b | 9 | 10 |
Useful: Quiz | Forums | Privacy Policy | Terms and Conditions

Linuxzoo created by Gordon Russell.
@ Copyright 2004-2024 Edinburgh Napier University