Tag Info

Hot answers tagged

60

The Windows equivalent in command.com, cmd, and other variants is type. From the Wikipedia article (emphasis mine): In computing, type is a command in various VMS. AmigaDOS, CP/M, DOS, OS/2 and Microsoft Windows command line interpreters (shells) such as COMMAND.COM, cmd.exe, 4DOS/4NT and Windows PowerShell. It is used to display the contents of ...


17

Take a look at tail, more precisecly, it's --lines=+N switch: tail --lines=+100 <file>


16

A GNU package, source-highlight, seems to do the trick (though isn't using cat -- as John T points out, this isn't possible with cat specifically). It's available via apt-get on Ubuntu, and requires the Boost regex library. Check your package manager to see if both are available, otherwise you can grab them from the web. The GNU page linked earlier has a ...


16

Because it opens and truncates the file before reading the data — it being shell, the redirections are processed by shell before even starting cat.


16

You can use this command: wc -l <file> This will return the total line number count in the provided file.


16

Seven. But seriously, it's hard enough to know how long a disk will last while idling let alone under heavy load. There's no answer other than to say it will probably wear the disk faster. The better argument against this is it would generally be quite slow. Why would you need to hammer the disk like that? If you're looking to find out when something ...


16

It may have no effect at all, depending on the size of somefile.txt - if it's small enough for the kernel to cache it in RAM, the file will only be read once from disk and subsequent iterations will retrieve it from the cache. Even if running that command repeatedly does have an effect on your drive's lifetime, it will be due to the file being read ...


16

No, you didn't. Think about it – you only displayed on screen the exact same data that is already stored on your harddisk. And if anyone could access your scrollback or your history, they could just as well read the id_rsa file directly. Besides, your shell's history – even if it was readable to other users (which it isn't) – only contains commands, not ...


14

From the command shell: copy a.txt + b.txt + c.txt output.txt (But that follows the command shells use of control-Z as an end of file marker, so not suitable in some cases). In PowerShell: get-content a.txt,b.txt,c.txt | out-file output.txt and you can control (using -Encoding parameter) the file encoding (which allows transcoding by using different ...


13

http://en.wikipedia.org/wiki/Stat_(system_call) Criticism of atime Writing to a file changes its mtime and ctime, while reading a file changes its atime. As a result, on a POSIX-compliant system, reading a file causes a write, which has been criticized. This behaviour can usually be disabled by adding a mount option in /etc/fstab. However, turning off ...


13

The > redirection happens first and opens file.txt for writing which clears any existing content.


12

It's useless in the sense that using it like that doesn't accomplish anything the other, possibly more efficient options can't (i.e. producing proper results). But cat is way more powerful than just cat somefile. Consult man cat or read what I wrote in this answer. But if you absolutely positively only need the contents of a single file, you might get some ...


11

Press Control-D.


10

In every day command line use it's not really much different. You especially aren't going to notice any speed difference since the time on CPU avoided by not using cat, your CPU is just going to be idle. Even if you're looping through hundreds or thousands (or even hundreds of thousands) of items in all practicality it's not going to make much difference, ...


9

I think the position being taken by some of those commenting on something being a UUOC is that if one really understands Unix and shell syntax, one would not use cat in that context. It's seen as like using poor grammar: I can write a sentence using poor grammar and still get my point across, but I also demonstrate my poor understanding of the language and ...


9

ls *.txt | xargs cat >> all.txt might work a bit better, since it would append to all.txt instead of creating it again after each file. By the way, cat *.txt >all.txt would also work. :-)


9

To output syntax highlighted code with something like cat, I created a ccat command by following the instructions at http://scott.sherrillmix.com/blog/programmer/syntax-highlighting-in-terminal/. #!/bin/bash if [ ! -t 0 ];then file=/dev/stdin elif [ -f $1 ];then file=$1 else echo "Usage: $0 code.c" echo "or e.g. head code.c|$0" exit 1 fi ...


7

The most obvious way is tail, the syntax might be slightly different depending on what OS you are using: tail -n +70000 If you can not get tail to work, you could use sed, but it might end up slower. sed -pe '1,69999d'


7

This is what wildcards and brace expansion are for. See if echo file.bz2.part-* returns the filenames in the desired order, and use cat file.bz2.part-* > file.bz2 if it does. Otherwise, figure out some other more complex expansion that does.


7

You have to send an EOF (^D) character on the standard input to tell cat to stop.


7

The obviously easy solution would be to not use cat. Your shell isn't a text viewer. Use less which is designed for this.


7

cat file1.txt folder1/file2.txt folder2/file3.txt > single.txt


7

Heredoc usage, or "appending to EOF", is not the problem. All redirections (including >) are applied before executing the actual command. In other words, your shell first tries to open /etc/php5/apache2/php.ini for writing using your account, then runs a completely useless sudo cat. One way to get around this: sudo bash -c "cat >> ...


7

You can use find (man page) to accomplish this: find -name "*.java" -exec cat {} \; You can also add a -print before the -exec to print the file name before each cat operation


7

tail supports several files, for example: tail -q -f file1 file2


6

Redirecting. At the end of any command, type > filename.txt. Replace filename.txt with the file name you want to use. You can even output to different devices (dangerous) or directories (ls > /home/user/ls.txt for example) As @Josh pointed out as well: If you need to see the output too you can use the tee command to output to stdout as well as a ...


6

Try quoting the first EOF, e.g., cat <<'EOF' >checkup.sh\n'$command' EOF This is explained in the bash(1) man page, in the section, Here Documents.


6

Type Ctrl+D at the start of a new line. ^D is the "end of file" character when typed from a keyboard. Note that the ^D character itself is not entered into the file. The file ends just before the point where you type ^D.


5

You're telling cat to send nothing to a file. Use touch (as mentioned) instead.


5

xclip can't talk to your X server. Check that $DISPLAY is set correctly. Do other X clients work with the same $DISPLAY setting? This: $ echo 'hello' | xclip works just fine for me. edit You get the error after su'ing to another user because that user doesn't have appropriate permissions to connect to your X server. X uses a permission checking ...



Only top voted, non community-wiki answers of a minimum length are eligible