Category Archives: Commands

File Commands :- Wildcards (LINUX)

wildcard is a symbol used to replace or represent one or more characters. They are used  to find the file and directory names which increases the flexibility and  efficiency of searches.

  1. *   :-  Asterisk symbol is used to represent any character(s).
  2. ?  :-  Question mark represents any single character.
  3. []  :-  Square brackets represents a range of characters.

How to use :-
* (Asterisk) Wildcard :-

-> $  ls .txt   :- This would list all the files having .txt extension .
-> $  ls *mom  :- This would list all the files that have the letters “mom” anywhere in their filenames.
-> $  ls a*  :- This would list all the files starting with letter a.
-> $  ls *z  :-
This would list all the files ending with letter z.

? (Question Mark) Wildcard

-> $ ls file?  :- This would list all the files that begin with “file” and have one more valid character.(file?.txt for files having extension as txt)
-> $ ls  ?i*  :-  This would list all the files whose second letter is i .
-> $ ls *.???  :- This would list all the files having three letter extension.

[] (Square Brackets) Wildcard

-> $ ls [fg]  :- This would list every file whose name either begins with a f or g.
-> $ ls [p-s]  :– This would list all files that start with “p,q,r or s”.
-> $ ls a[p-s]  :- This would list all files start with the letter “a”  and second letter contains “p,q,r or s”.
-> $ ls [a-c,A-C] :- This would list all files start with the letter “a,b,c,A,B,C”. The [ , ] imply that this entire range indicates ONLY ONE letter which can be from any of the two given sub-ranges.
-> $ ls .[tx]  :- This would list all the files that have extension that begins with t or x.
-> $ ls [!a-c]  :- This would list all files except those that start with “a, b or c”.

Directory Commands

  1. pwd  :-  pwd stands for “Print working Directory”. This command allows you to know the current directory in which you               are located.
  2. cd  :-  .Change directory 
    This command allows you to change the directories.
    cd /home :- (root directory) Change the current working directory to /home.
    cd ..  :- Change to parent directory of current directory.
    cd ~  :-  This allows to move to the user’s home directory as : /home/user
  3. Create and Delete directories 
    mkdir dname :- This command will create a new directory named as dname.
    rmdir dname :- This command will delete the dname directory (Empty directory)
    rm -r d   :-  It allows to remove directories and their contents recursively.
  4. ls  – List information about the files (by default current directory )
    ls -l  :- list all file/directory information in current directory(long version)
    ls -a :- list hidden files ( It will not ignore entries starting with . )
    ls -R :- (List Sub-directories) list current directory and all other directories within current directory.
    ls -r  :- list in reverse alphabetically order.