Executing a background job

Appending an ampersand ( & ) to the command runs the job in the background.

For example, when you execute a find command that might take a lot time to execute, you can put it in the background as shown below. Following example finds all the files under root file system that changed within the last 24 hours.

find / -ctime -1 > /tmp/changed-file-list.txt &

Sending the current foreground job to the background using CTRL-Z and bg command

You can send an already running foreground job to background as explained below:

Press CTRL+Z which will suspend the current foreground job. Execute bg to make that command to execute in background. For example, if you’ve forgot to execute a job in a background, you don’t need to kill the current job and start a new background job. Instead, suspend the current job and put it in the background as shown below.

find / -ctime -1 > /tmp/changed-file-list.txt

[CTRL-Z]
[2]+  Stopped                 find / -ctime -1 > /tmp/changed-file-list.txt

bg

View all the background jobs using jobs command

You can list out the background jobs with the command jobs. Sample output of jobs command is

jobs
[1]   Running                 bash download-file.sh &
[2]-  Running                 evolution &
[3]+  Done                    nautilus .

Taking a job from the background to the foreground using fg command

You can bring a background job to the foreground using fg command. When executed without arguments, it will take the most recent background job to the foreground.

fg

If you have multiple background jobs, and would want to bring a certain job to the foreground, execute jobs command which will show the job id and command.

In the following example, fg %1 will bring the job#1 (i.e download-file.sh) to the foreground.

jobs
[1]   Running                 bash download-file.sh &
[2]-  Running                 evolution &
[3]+  Done                    nautilus .

# fg %1

Kill a specific background job using kill %

If you want to kill a specific background job use, kill %job-number. For example, to kill the job 2 use

kill %2

All the above contents are taken from this link.

Answer from Ramesh on Stack Exchange
🌐
Arch Linux Man Pages
man.archlinux.org › man › extra › z › z.1.en
z(1) — Arch manual pages
Arch Linux · Home · Packages ... directory that matches ALL of the regexes given on the command line, in order. For example, z foo bar would match /foo/bar but not /bar/foo....
🌐
InterServer
interserver.net › home › linux and commands › unix z commands
Unix Z Commands - Interserver Tips
April 23, 2026 - In this example we are searching for multiple patterns within a compressed file with the help of zegrep ... If you need any further assistance please contact our support department. Self-Hosted Video Processing With FFmpeg: A Practical Guide · How to use nohup: Commands in Linux That Survive Terminal Closes
🌐
GitHub
github.com › rupa › z
GitHub - rupa/z: z - jump around · GitHub
After a short learning phase, z will take you to the most 'frecent' directory that matches ALL of the regexes given on the command line, in order. For example, z foo bar would match /foo/bar but not /bar/foo.
Starred by 17K users
Forked by 1.2K users
Languages   Shell 64.6% | Roff 35.0% | Makefile 0.4%
🌐
GitHub
github.com › agkozak › zsh-z
GitHub - agkozak/zsh-z: Jump quickly to directories that you have visited "frecently." A native Zsh port of z.sh with added features. · GitHub
Zsh-z is a command-line tool that ... predicts where you want to go when you type a partial string. For example, z src might take you to ~/src/zsh....
Starred by 2.4K users
Forked by 79 users
Languages   Shell
Top answer
1 of 1
3

Executing a background job

Appending an ampersand ( & ) to the command runs the job in the background.

For example, when you execute a find command that might take a lot time to execute, you can put it in the background as shown below. Following example finds all the files under root file system that changed within the last 24 hours.

find / -ctime -1 > /tmp/changed-file-list.txt &

Sending the current foreground job to the background using CTRL-Z and bg command

You can send an already running foreground job to background as explained below:

Press CTRL+Z which will suspend the current foreground job. Execute bg to make that command to execute in background. For example, if you’ve forgot to execute a job in a background, you don’t need to kill the current job and start a new background job. Instead, suspend the current job and put it in the background as shown below.

find / -ctime -1 > /tmp/changed-file-list.txt

[CTRL-Z]
[2]+  Stopped                 find / -ctime -1 > /tmp/changed-file-list.txt

bg

View all the background jobs using jobs command

You can list out the background jobs with the command jobs. Sample output of jobs command is

jobs
[1]   Running                 bash download-file.sh &
[2]-  Running                 evolution &
[3]+  Done                    nautilus .

Taking a job from the background to the foreground using fg command

You can bring a background job to the foreground using fg command. When executed without arguments, it will take the most recent background job to the foreground.

fg

If you have multiple background jobs, and would want to bring a certain job to the foreground, execute jobs command which will show the job id and command.

In the following example, fg %1 will bring the job#1 (i.e download-file.sh) to the foreground.

jobs
[1]   Running                 bash download-file.sh &
[2]-  Running                 evolution &
[3]+  Done                    nautilus .

# fg %1

Kill a specific background job using kill %

If you want to kill a specific background job use, kill %job-number. For example, to kill the job 2 use

kill %2

All the above contents are taken from this link.

🌐
Medium
medium.com › @sybrenbolandit › z-command-a2940c206278
Z COMMAND. Working from the command line can be… | by Sybren Boland | Medium
July 27, 2021 - This post states one more tool you can use to power up your command line. Previously I posted fish shell as a first superpower. This time we see how to jump around in your directories. Installing on a mac can be done first installing fisher (github): curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish ... A prerequisite is that you have navigate to the target directory after you installed z.
🌐
Nitinfotech
nitinfotech.com › home › tech solutions › linux › a-z linux commands: comprehensive overview with examples
A-Z Linux Commands: Comprehensive Overview with Examples - Nit Infotech
June 22, 2024 - This list covers many of the commonly used commands in Linux. Each command has a basic example to demonstrate its usage.
🌐
TecMint
tecmint.com › home › a – z linux commands – overview with examples
A - Z Linux Commands - Overview with Examples
January 17, 2023 - To learn more about bg command, read: Start Linux Command in Background and Detach Process in Terminal · bzip2 command is used to compress or decompress file(s). $ bzip2 -z filename #Compress $ bzip2 -d filename.bz2 #Decompress · To learn more examples on bzip2, read: How to Compress and Decompress a .bz2 File in Linux
Find elsewhere
Top answer
1 of 2
5

1) Your code is not correct, you missed one ] bracket somewhere. Probably after [ -z "$2" block.

2) if statement executes following command(s) and then executes block of code enclosed in then .. fi or then .. else keywords if the return value of the command(s) is true (their exit code is 0)

3) [ is just an alias for the test command (try man test). This command takes several parameters and evaluates them. For example, used with -z "$something" flags would return true (0) if $something is not set or is an empty string. Try it:

if [ -z "$variable" ]; then
    echo Variable is not set or is an empty string
fi

4) || statement is an OR. Next command would be executed if the previous one returned false statement. So in the statement

if [ -z "$variable" ] || [ -z "$variable2" ]; then
    echo Variable 1 or variable 2 is not set or is an empty string
fi

command [ -z "$variable2" ] would be executed only if variable was empty. The same could be achieved with different syntax:

if [ -z "$variable" -o -z "$variable2" ]; then
    echo Variable 1 or variable 2 is not set or is an empty string
fi

which should be faster, because it requires only one instance of the test program to be run. Flag -o means OR, so you could read it as: If variable is not set/empty OR variable2 is not set/EMPTY...

5) Statement "[ ${3:-} ]" means return true if $3 (the third argument of the script) is set.

6) >&2 is a stream redirection. Every process has two outputs: standard output and error output. These are independent and could be redirected (for example) to be written to two different files. >&2 means "redirect standard output to the same location as standard error".

So to sum up: commands between then .. fi will be executed IF the script is run with $1 empty or $2 empty or $3 NOT empty That means that the script should be run with exactly two parameters. And if not, the echo message will be printed to standard error output.

2 of 2
3

-z STRING means the length of STRING is zero.

${parameter:-word} If parameter is unset or null, the expansion of word is substituted. In your case $3 is just set with a blank value, if $3 do not have any value.

&2 writes to standard-error. I mean the stdout value of the executed command is sent to stderr,

🌐
TurtleBytes Suite
turtlebytes.com › blog › linux-z-command-is-a-must-have-terminal-tool
Linux 'z' command is a must have terminal tool - TurtleBytes
January 12, 2026 - Once you have visited a directory even once, z remembers it. ... That single command can take you straight to a deeply nested directory under /var/www without you needing to remember or type the full path.
🌐
Linux Handbook
linuxhandbook.com › a-to-z-linux-commands
A to Z Linux Commands
October 29, 2022 - The basename command in Linux prints the final component in a file path. Learn some practical examples of using basename command in bash scripts.
🌐
Landoflinux
landoflinux.com › linux_z_commands.html
Remover Malware Virus – Ajudá-lo a remover o vírus e malware com Facilidade
June 22, 2014 - Eliminar Boot.Cryptolocker.AU Eliminar DiscoverLiveRadio Toolbar Eliminar PUP.TrumpKard Eliminar Search.Protectedio.com Eliminar Search.tapufind.com Eliminar SearchWebMe.com Eliminar Support-online-pc.site Eliminar Total Deal Search Ads Eliminar zCrypt ransomware Excluir Boot.Cryptolocker.AU Excluir DiscoverLiveRadio Toolbar Excluir PUP.TrumpKard Excluir RunBooster Excluir Search.Protectedio.com Excluir Search.tapufind.com Excluir SearchWebMe.com Excluir Support-online-pc.site Excluir Total Deal Search Ads Excluir zCrypt ransomware Limpar Boot.Cryptolocker.AU Limpar DiscoverLiveRadio Toolbar L
🌐
Linux Command Library
linuxcommandlibrary.com › man › z
z man | Linux Command Library
Multiple arguments are matched in order: z foo bar matches paths containing "foo" followed by "bar".The database is stored in ~/.z by default and is updated automatically when changing directories (via a shell hook).
🌐
LearnByExample
learnbyexample.github.io › learn_gnused › z-s-and-f-command-line-options.html
z, s and f command line options - CLI text processing with GNU sed
NUL separation is very useful to separate filenames since the names cannot have the NUL character. For example, grep -Z and find -print0 will print NUL separated filenames whereas grep -z and xargs -0 will accept NUL separated input.
🌐
LinuxLinks
linuxlinks.com › home › z – jump around the filesystem
z - jump around the filesystem - LinuxLinks
October 14, 2023 - It is not intended as a substitute for the cd command. Option to restrict matches to subdirectories of the current directory. Option to match by rank only. Option to match by recent access only. Remove the current directory from the data file. Support for tab completion. Website: github.com/rupa/z Support: Wiki Developer: Rupa Deadwyler License: WTFPL license
🌐
Fossbytes
fossbytes.com › home › more › list › the ultimate a to z list of linux commands | linux command line reference
The Ultimate A To Z List of Linux Commands | Linux Command Line Reference
January 25, 2022 - Linux distributions can leverage an extensive range of commands to accomplish various tasks. For most Linux distros, bash (bourne again shell) is the default command-line interface or shell used to execute these commands. In this A to Z list of Linux commands, we have tried to include as many ...
🌐
Linux Hint
linuxhint.com › z-mean-in-bash
What Does -z Mean in Bash – Linux Hint
The -z option returns true if the ... the test command is as follows: if [ -z "$string" ]; then # string is empty else # string is not empty fi · The -z option is used to test whether the variable “string” is empty so if the variable is empty, the script executes the code in the “if” ...
🌐
Mskelton
mskelton.dev › bytes › zoxide-a-smarter-cd-command
Zoxide, A Smarter cd Command - Mark Skelton
March 23, 2024 - With that in place, we can now use the z command as an alternative to the cd command. The z command works exactly like cd but with some additional features. For example, you can use z - to jump to the last directory you were in, or z data to jump to the most used directory that contains the ...
🌐
Quora
quora.com › What-does-Z-mean-in-Linux
What does Z mean in Linux? - Quora
Answer: Well, there are many things you could be talking about, but since I can’t read your mind, I’m going to just pick one of my favorites. Let’s say you run the “ps” command to see what processes are running on your system, and under the STAT column you see the letter Z: [code]527 ...