Running multiple commands in one single line (Linux)

Configurare noua (How To)

Situatie

Assuming you have to execute multiple commands, if you would do this one by one, you have to be in front of the keyboard and wait for each command to complete and then execute the other.

Solutie

In order to avoid this tine consuming activity you can group the commands and execute them in the same line, as:

Syntax: 
command_1; command_2; command_3
or 
command_1 && command_2 && command_3

i.e.:

mkdir test; cd test; touch test_write; ls -l test_write; rm test_write; pwd
or
mkdir test; cd test; touch test_write; ls -l test_write; rm test_write; pwd

Output sample:

--- snip ---

[root@linux_host 18gi_cluster_oraarch]# mkdir test; cd test; touch test_write; ls -l test_write; rm test_write; pwd
-rw-r--r--. 1 root root 0 Feb 11 12:41 test_write
/mnt/stage/Testing/sciobote/BACKUP/18gi_cluster_oraarch/test

[root@linux_host test]# mkdir test && cd test && touch test_write && ls -l test_write && rm test_write && pwd
-rw-r--r--. 1 root root 0 Feb 11 12:42 test_write
/mnt/stage/Testing/sciobote/BACKUP/18gi_cluster_oraarch/test

--- snip ---

Tip solutie

Permanent

Voteaza

(28 din 53 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?