Use wc
:
wc -l <filename>
This will output the number of lines in <filename>
:
$ wc -l /dir/file.txt 3272485 /dir/file.txt
Or, to omit the <filename>
from the result use wc -l < <filename>
:
$ wc -l < /dir/file.txt 3272485
You can also pipe data to wc
as well:
$ cat /dir/file.txt | wc -l 3272485 $ curl yahoo.com --silent | wc -l 63
Related Posts:
- Why do you need to put #!/bin/bash at the beginning of a script file?
- How does “cat << EOF" work in bash?
- Bash script: bad interpreter
- What does `set -x` do?
- How do I know the script file name in a Bash script?
- What is “-bash: !”: event not found”
- How can I fully log all bash scripts actions?
- How do I deal with a filename that starts with the hyphen (-) character?
- Bash: No such file or directory?
- “Couldn’t find a file descriptor referring to the console” on Ubuntu bash on Windows
- How do I parse command line arguments in Bash?
- gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now
- Pass a password to ssh in pure bash
- -bash: syntax error near unexpected token `newline’ for display command
- How do I use grep to search the current directory for all files having the a string “hello” yet display only .h and .cc files?
- “sed” command in bash
- Explaining the ‘find -mtime’ command
- Pseudo-terminal will not be allocated because stdin is not a terminal
- Extract file basename without path and extension in bash
- Given two directory trees, how can I find out which files differ by content?
- mv: cannot stat error : No such file or directory error
- How to change the output color of echo in Linux
- Diff command along with Grep gives “Binary file (standard input) matches”
- Pseudo-terminal will not be allocated because stdin is not a terminal
- ./configure : /bin/sh^M : bad interpreter
- Trying to use bash on Windows and got no installed distributions message
- What is the difference between “#!/usr/bin/env bash” and “#!/usr/bin/bash”?
- -bash: fork: Cannot allocate memory
- Is there a “goto” statement in bash?
- How to get the process ID to kill a nohup process?
- Writing a simple shell in C using fork/execvp
- chmod: changing permissions of ‘my_script.sh’: Operation not permitted
- tar: add all files and directories in current directory INCLUDING .svn and so on
- What does set -e mean in a bash script?
- What does set -e mean in a bash script?
- How to recursively download a folder via FTP on Linux
- “find: paths must precede expression:” How do I specify a recursive search that also finds files in the current directory?
- Bash script prints “Command Not Found” on empty lines
- Pipe to/from the clipboard in a Bash script
- Linux Bash: Move multiple different files into same directory
- How do I write stderr to a file while using “tee” with a pipe?
- How to include file in a bash shell script
- How to enable Bash in Windows 10 developer preview?
- What does ‘bash -c’ do?
- Delete .DS_STORE files in current folder and all subfolders from command line on Mac
- bash sh – command not found
- How to remove all plugins, posts, pages, and inactive themes in one line with wp-cli? WordPress bloatware removal
- How can I sort du -h output by size
- What are the functional differences between .profile .bash_profile and .bashrc
- How to run a command multiple times, using bash shell?
- How do I prevent accidental rm -rf /*?
- How do I sleep for a millisecond in bash or ksh
- What’s the best way to check if a volume is mounted in a Bash script?
- Keeping a linux process running after I logout
- What useful things can one add to one’s .bashrc? [closed]
- How to add a timestamp to bash script log?
- Colors in bash after piping through less?
- Linux command line best practices and tips?
- How to run command as user who has /usr/sbin/nologin as Shell?
- How to get pid of just started process
- Can you have more than one ~/.ssh/config file?
- SSH from A through B to C, using private key on B [closed]
- How to apply a filter to real time output of `tail -f `?
- How to remove invalid characters from filenames?
- zcat/gzcat works in linux, not on osx. general linux/osx compatibility
- How do I grep recursively?
- SSH using python script
- Changing the resolution of a VNC session in linux
- How do I compare two string variables in an ‘if’ statement in Bash?
- What is difference between arm64 and armhf?
- standard_init_linux.go:178: exec user process caused “exec format error”
- Can you Run Xcode in Linux?
- Implementation of multiple pipes in C
- make -j 8 g++: internal compiler error: Killed (program cc1plus)
- Error handling in Bash
- how to search for a directory from the terminal in ubuntu
- How to use dos2unix?
- How to add a default include path for GCC in Linux?
- Timeout a command in bash without unnecessary delay
- How to configure both webserver and appserver for WordPress CMS?
- Communcation with wordrpess and linux server [closed]
- Why is my crontab not working, and how can I troubleshoot it?
- Why is “chmod -R 777 /” destructive?
- How to check if a library is installed?
- Is it normal to get hundreds of break-in attempts per day?
- What does Virtual memory size in top mean?
- How do I find the UUID of a filesystem
- Find out symbolic link target via command line
- Meaning of directories on Unix and Unix like systems
- How to handle security updates within Docker containers?
- Is it possible to make Nginx listen to different ports?
- REJECT vs DROP when using iptables
- How to disable everything in crontab -l?
- df says disk is full, but it is not
- What is the maximum port number?
- How to sort ps output by process start time?
- Is there a proper way to clear logs?
- protocol version mismatch — is your shell clean?
- How do I join two named pipes into single input stream in linux
- How should an IT department choose a standard Linux distribution?