Skip to main content

Posts

Linux List Users Command

To list only usernames type the following awk command: $ awk -F':' '{ print $1}' /etc/passwd Second Way: sed 's/:.*//g' /etc/passwd Third Way: cut -d: -f1 /etc/passwd
Recent posts

A command to list all users? And how to add, delete, modify users?

I need a command to list all users in terminal. And how to add, delete, modify users from terminal. Solution:   To list all local users you can use: cut -d: -f1 /etc/passwd To list all users capable of authenticating (in some way), including non-local, see this reply: https://askubuntu.com/a/414561/571941 Some more useful user-management commands (also limited to local users): To add a new user you can use: sudo adduser new_username or: sudo useradd new_username See also: What is the difference between adduser and useradd? To remove/delete a user, first you can use: sudo userdel username Then you may want to delete the home directory for the deleted user account : sudo rm -r /home/username (Please use with caution the above command!) To modify the username of a user: usermod -l new_username old_username To change the password for a user: sudo passwd username To change the shell for a user: sudo chsh username To change the details for a user (for example real name): sudo chfn usern

Practical examples of Touch command on Linux

Linux Touch command The touch command can be used to modify the access/modification timestamps of files. It is more often used to actually just create an empty file quickly. This post shows some very simple and quick examples of using the touch command to modify timestamps or create files. 1. Create a blank file To simply create a blank file with touch command, use the syntax below. $ touch abc.txt If the file already exists, its access time will be updated. 2. Create multiple files with touch To create multiple files, specify their names together separated by a space. $ touch abc.txt cde.txt xyz.txt 3. Create lots and lots of files If for some reason you wish to create lots of files, then commands like these would be very helpful # Create files with names A to Z $ touch {A..Z} # Create files with names 1 to 20 $ touch {1..20} # Create files with extension $ touch {1..1000}.txt # Create 10K files $ touch {1..10}{1..1000} And then use the ls command to see what all has been created. 4.

Find filenames list by content search and file format

Generally computer users can memorize the locations of different files that they read or store. As the number of files increases, they can use descriptive filenames making it easy to guess the content by looking at the file name. However when the number of files grows higher & higher in number, it becomes a pain to remember locations or filenames. Also when a computer is used by some other person than the owner, it becomes even harder to locate some files. Search by partial name find -name "<filename pattern>" Above command is useful only if you can remember the filenames at least some parts of the file name. If you are a software developer, you know how many times you would want to search files based on the content. Search by content find <path> -name "<file name pattern>" -exec grep -l "<text to search>" {} \; Above command can be used to find the files based on content search. For example to find a file with a value say &quo

grep Word Count Command

How do I count words using grep command under Linux / Unix like operating systems? You can pass the -c option to grep command to suppress normal output and display a count of matching lines for each input file. The syntax is follows: grep -c "string" file In this example, search for a word called ‘var’ and display a count of matching lines: grep -c 'var' /etc/passwd You can pass the -v option to count non-matching lines: grep -v 'var' /etc/passwd However, this will not count words. To count exact matched words, enter: grep -o -w 'word' /path/to/file/ | wc -w The grep -o command will only display matched words and the wc -c command will display the word counts.

A Brief History of the UNIX and Linux Operating Systems

Understanding the origin and evolution of a particular technology often helps when learning how to use it. Like many new technologies, the development of these two operating systems did not start as a conscious effort to develop a commercial product. This makes their current level of popularity and utilization even more remarkable. - The UNIX Operating System - The Linux Operating System Operating System Concepts Most operating systems have certain traits that differentiate them from each other. The UNIX and Linux operating systems are no exceptions to this fact. Having a general understanding of a few of the design traits for these operating systems will assist you in using them more effectively. - The UNIX and Linux operating system environment - The File system - The superuser (root) account Getting Connected, Logging in, and Logging out Before using a computer system, you need to connect and in most cases be authenticated as a valid system user. Methods for connecting and being au

Grep Command Examples of How to Search a File for a Pattern

The UNIX Grep command searches files for a user-specified text pattern. It returns a list of the matching words or shows each line of text that contains them. You can broaden the results by using wildcards. Grep also has the ability to count instances of a search phrase that appear in a file. The syntax for this UNIX command includes three parameters, but only the text pattern is required: grep [options] pattern [filename] If it contains multiple words or special characters, be sure to place single quotation marks before and after the pattern. The UNIX shell does not interpret dollar signs, brackets, parentheses, pipes or asterisks in the same way as letters. For example, an asterisk is treated as a wildcard when you don't use quotes. If you leave out the filename, UNIX will collect data from the standard input device. This is usually the keyboard. (1) Basic search with no options The following example shows what happens if you use grep to search for the word "unix&