for command in Linux with Examples Last Updated : 27 Sep, 2024 Comments Improve Suggest changes Like Article Like Report IntroductionThe for command in linux used in shell scripting to iterate over a set of values or perform set of tasks repeatedly. The for loop allows users to automate operations efficiently which is easier to maintain.Syntax: for NAME [in WORDS ... ] ; do COMMANDS; doneHere NAME takes the value of each item in the list.WORDS contains a set of values.COMMANDS contains a set of actions to perform.Example:for i in 0 1 2 3 4 do echo "$i" doneOutputOptions used with for loop :optionDescriptionfor var in *Iterate through all files in the current directoryfor var in {start..end}Loop through a sequence of numbers or charactersfor var in $(command)Iterate through the output of a commandIterating over files in a directory :for file in *; do echo "$file" doneOutput The above image kept for reference. There are so many rows for this output.Iterating over a range of numbers : for i in {1..5}; do echo "Number $i" doneOutput : Using command output : for process in $(ps -e | awk '{print $1}'); do echo "Process ID: $process" doneOutput : The above image kept for reference. There are so many rows for this output.Options: help for : It displays help information. Conclusion The for command in linux is essential tool in shell scripting. Whether iterating over files, lists the for loop enhances productivity. Understanding its various forms and applications allow users to write more powerful scripts which can create robust solutions. Comment More infoAdvertise with us D DrRoot_ Follow Improve Article Tags : Technical Scripter Linux-Unix Technical Scripter 2018 linux-command Linux-Shell-Commands +1 More Similar Reads factor command in Linux with examples The factor command in Linux is used to print the prime factors of the given numbers, either given from the command line or read from standard input. The numbers given through standard input may be delimited by tabs, spaces or newlines. Syntaxfactor [NUMBER]You can provide one or more numbers as argu 2 min read fc Command in Linux with Examples As we all know that LINUX is command friendly and while working on LINUX, you may deal with very long commands that may include long paths or really difficult syntax, and imagine what if working with such commands you do a minor mistake which will require re-writing of the entire command synopsis an 3 min read fc-cache command in Linux with Examples The fc-cache command in Linux scans the font directories and build font cache for applications which use fontconfig for their font handling. When no arguments are passed fc-cache scans each directory for font files readable by FreeType. A cache is created which contains properties of each font and t 2 min read fc-list command in Linux with examples fc-list command is a part of the fontconfig system. It is used to list the available fonts and font styles. Using the format option, the list of all fonts can be filtered and sorted out. Moreover, multiple parameters can be passed to it after a colon symbol (:) to restrict the information that is be 3 min read fdisk command in Linux with examples The 'fdisk' command in Linux, short for "format disk," is a powerful, dialog-driven utility used for creating and manipulating the disk partition table. Essential for system administrators and users looking to manage their hard driveâs structure, 'fdisk' supports a range of operations such as creati 5 min read fg command in Linux with examples The fg command in Linux is used to bring a background job into the foreground. It allows you to resume a suspended job or a background process directly in the terminal window, so you can interact with it.Syntaxfg [job_spec]The job_spec is a way to refer to the background jobs that are currently runn 3 min read fgrep command in Linux with examples The 'fgrep' filter is used to search for the fixed-character strings in a file. There can be multiple files also to be searched. This command is useful when you need to search for strings that contain lots of regular expression metacharacters, such as "^", "$", etc. This makes 'fgrep' particularly v 4 min read file command in Linux with examples The 'file' command in Linux is a vital utility for determining the type of a file. It identifies file types by examining their content rather than their file extensions, making it an indispensable tool for users who work with various file formats. The file type can be displayed in a human-readable f 3 min read How to Find a File in Linux | Find Command The find command in Linux is used to search for files and directories based on name, type, size, date, or other conditions. It scans the specified directory and its sub directories to locate files matching the given criteria.find command uses are:Search based on modification time (e.g., files edited 9 min read Finger command in Linux with Examples The 'finger' command is a powerful utility in Linux used to display information about users logged into the system. This command is commonly used by system administrators to retrieve detailed user information, including login name, full name, idle time, login time, and sometimes the user's email add 4 min read Like