Thursday, 18 October 2018

Create files and Directory with Single Linux Command


In linux to create a direcotry use mkdir command and to create a file use touch command.

To create a new directory

[sysads@sysads ~]$  mkdir folder

To create a new directory with sub-directories,

[sysads@sysads ~]$  mkdir -p folder_1/folder_11/folder_111

              -p  ----> --parents (no error if existing, make parent directories as needed )


To create a new directory with multiple sub-directories,

[sysads@sysads ~]$  mkdir -p folder_2/{folder_21,folder_22,folder_23,folder_24,folder_25}

To create a new directory with multiple sub-directories and sub-directories with multiple sub-directories,

[sysads@sysads ~]$  mkdir -p folder_3/{folder_31/{folder_311,folder_312},folder_32,folder_33}


To create an n number of folders where the numbers increment

[sysads@sysads ~]$  mkdir -p folder_100/folder_1{01..20}

To create an n number of files with extension (i.e .txt) where the numbers increment

[sysads@sysads ~]$  touch folder_100/file_1{01..20}.txt

No comments:

Post a Comment