Hot answers tagged

48

convert, the ImageMagick utility used in Ketan's answer, also allows you to write something like convert xc:none -page Letter a.pdf or convert xc:none -page A4 a.pdf or (for horizontal A4 paper) convert xc:none -page 842x595 a.pdf etc., without creating an empty text file. @chbrown noticed that this creates a smaller pdf file. "xc:" means "X ...


28

There is a way better way of achieving this: less +F <file> It'll show you the whole file, has the full power of less and will wait for new input. If you want to stop waiting for input, and read a specific part, you can stop it with ^C and resume with F. The F command is always available in less, if you decide to watch for changes while having a ...


27

Like the smallest possible GIF, the smallest possible blank-page PDF needs to be worked out by hand, because it's so small that unnecessary-but-harmless bits of metadata become a significant part of the file size, and compression actually makes things bigger. It also requires careful attention to the rules in the PDF specification about what bits of the ...


27

tail lets you add -n to specify the number of lines to display from the end, which can be used in conjunction with -f. If the argument for -n starts with + that is the count of lines from the beginning (0 and 1 displaying the whole file, 2 indicating skip the first line, as indicated by @Ben). So just do: tail -f -n +0 filename If your log files get ...


24

If you have convert (an ImageMagick utility) installed, you could do this: touch a.txt && convert a.txt -page Letter a.pdf


14

Just copy those lines to the hold buffer (then delete them) and when on last line append the content of hold buffer to pattern space: some command | sed '1,NUMBER{ # in this range H # append line to hold space and 1h # overwrite if it's the 1st line d ...


12

That's grep issue, not find. grep matches pattern using regular expression by default, the pattern schema_name. means any character follows the string schema_name. If you want to match the dot . literally, you have to escape it with a backslash \: find . -type f -name "*.sql" -exec grep -il 'schema_name\.' {} + or using -F option: find . -type f -name ...


10

You can use fdupes. From man fdupes: Searches the given path for duplicate files. Such files are found by comparing file sizes and MD5 signatures, followed by a byte-by-byte comparison. You can call it like fdupes -r /path/to/dup/directory and it will print out a list of dupes. Update You can give it try to fslint also. After setting up fslint, go to ...


9

An awk approach: cmd | awk -v n=3 ' NR <= n {head = head $0 "\n"; next} {print} END {printf "%s", head}' One benefit over @don_crissti's sed approach is that it still works (outputs the lines) if the output has n lines or fewer.


8

You could use pdfTeX: echo '\shipout\hbox{}\end' | pdftex which produces a blank single-page texput.pdf of about 900 bytes, half of what ImageMagick uses. This puts you at the mercy of the paper size default of your TeX installation, though. To set the size explicitly you can go to LaTeX instead: echo ...


8

echo .bp | groff -T pdf > t.pdf Brought to you by groff, the world's most underrated software.


8

It is because pdf is not plain text. cat can only print the file as-is. To see the contents of a pdf file using the command line, you can use pdftotext. pdftotext pdffile -


7

Given that the repository you're interested in is in your apt sources, you can find the information on the packages available there in the files apt downloads; for the line deb http://ftp.de.debian.org/debian jessie main non-free these would be respectively /var/lib/apt/lists/ftp.de.debian.org_debian_dists_jessie_main_binary-amd64_Packages ...


6

Pipelines run from left to right. More precisely, the processes run in parallel, but the data flows from left to right: the output of the command on the left becomes the input of the command on the right. Here the command on the left is grep tool. Since you're passing a single argument to grep, it's searching in its standard input. Since you haven't ...


6

In your first example cat f.txt | grep "someText" grep doesn't get a filename argument, only a string to search for. In that case grep will read the text to search from standard input. In this case that standard input is piped in from the output of cat f.txt, which outputs the content of the file not the filename. What you also could have done to make ...


6

You can make it shorter: find . ! -empty -type f -exec md5sum {} + | sort | uniq -w32 -dD Do md5sum of found files on the -exec action of find and then sort and do uniq to get the files having same the md5sum separated by newline.


6

I have xclip and with it this can be done in this way: ./a_command | xclip -in && xclip -o | tail -n +3 && xclip -o | head -n 2 Here is its description: xclip - command line interface to X selections (clipboard) NAME xclip - command line interface to X selections (clipboard) SYNOPSIS xclip [OPTION] [FILE]... DESCRIPTION ...


5

No, since ls (or any other file-operating process) is in the process state "uninterruptible sleep", there is nothing that can interrupt it, even SIGKILL can't. Maybe you can lower the timeout values when mounting remote filesystems. sshfs has ServerAliveInterval and ServerAliveCountMax.


5

My understanding of the question is that, you need to create a large file, each line of this file is a random word within specified length. If you don't need the word to be a real word, but some random characters: < /dev/urandom tr -d -c '[:alpha:]'|head -c 1M|fold -w10 >result.txt This will create a file of size 1M and each line with 10 random ...


5

ack does something smiliar to grep. When it puts it text to a terminal, it will spit the results out in color. If the output is redirected to a file, the matches do not get colorized. You can override these heuristics with the options --color and --nocolor. Check man 1 ack for more details.


5

Aptitude can search by archive name: aptitude search '~Ajessie' ~Aarchive (or, equivalently ?archive(archive)) is documented in the search term reference as Select packages from the given archive (such as “unstable”). If you want only the package names, then pass -F %p to format the output appropriately; by default you'll also get status and short ...


5

If you have gnu find - and assuming none of your file names contains newlines - you could use find's -printf to output the mtime in the desired format + the file name then run grep to get the count: find . -type f -printf '%TY-%Tm-%Td %TH:%TM %p: ' -exec grep -cw "whatever" {} \; | sort -k1,1 -k2,2 Alternatively, with zsh you could glob and sort by ...


4

You could use fgrep find . -type f -name "*.sql" -exec fgrep -i -l 'schema_name.' {} + which on older Unix operating systems may very well be a lot faster (fgrep, grep and egrep used to be 3 different executables, and there fgrep was a lot faster because it omitted everything related to regex entirely - on eg GNU based systems these three programs are ...


4

free is provided by procps-ng; Debian 8 has version 3.3.9, which uses the old style with a separate line for buffers/cache, while Gentoo and presumably RHEL 7.x have version 3.3.10 or later which uses the new style. You can see the reasoning behind the change in the corresponding commit message. If you really want the old-style output you can run an older ...


4

The feature you are looking for is there. You are just missing a * in your example. Type cat file000[1-3]*ESC* and it should work. I think this is the case because the readline function insert-completions (which is bound to ESC*) will not expand the glob pattern if it does not match any files. And without the last * it does not match the files. You can read ...


4

Your GUI explorer is using information from the avahi daemon which is listening for services on the local network. You can do the same from the cli with avahi-browse -rat


4

I can only address the first part of your question: You can view the dimensions of an image on the command line by the using the identify tool, part of the the imagemagick package. (To install imagemagick on a Debian box, provided you have sudo privileges, you can run sudo apt-get install imagemagick ). For example, in a directory with image file rose.jpg, ...


3

In addition to /u/Anthon's answer, you can do something like: { cat filename; tail -0f filename; } That -0 option to tail is equivalent to -n 0, meaning: dispaly 0 lines. But the -f will display new lines. You don't need the braces { }. I used them because sometimes you want to redirect the filedescriptors in some way. For instance: { cat ; tail -0f -; ...


3

That happened because the output you produced included codes that your terminal interface interpreted as control codes. This is normally resolved with either reset or stty sane.


3

What a sad thing having a VM without internet access :( I think that you should talk to your boss and tell him that without internet access you can't properly update your linux distro, and this can lead to potential security issues. Anyway, you can browse the Arch Linux official package list from here: https://www.archlinux.org/packages/ You can download a ...



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