Tag Info

Hot answers tagged

58

This used to be posted in the Usenet FAQs for Unix—I see it is in the GNU Core Utility FAQs. There were at least five different methods, but this works well: $ rm ./- If a filename contains untypeable characters, then use: $ rm -i * The -i flag asks for confirmation for each file if it should be removed or not.


37

Removing a file whose names starts with - is a FAQ, but it looks like you've got a different problem. Of the solutions you mentioned in the question: rm -- - That should work. rm "-" That's no different from rm -. The quotes are stripped by the shell, and the rm command just sees the single hyphen as an argument. Quotation marks are useful for ...


35

You may want to use the truncate command: truncate --size=1G test.txt SIZE can be specified as bytes, KB, K, MB, M, etc. I assume you can calculate the desired size by hand; if not, you could probably use the stat command to get information about the file's current size.


18

perl -we 'open( FILE, "< ./test.txt" ) && truncate( FILE, 8 ) && close(FILE);' opens the file for reading. However, to truncate the file you need to modify it, so a read-only file handle isn't going to work. You need to use the "modify" mode ("+>"). As a side issue, it always amazes me when people let system calls fail silently and ...


18

If you want something safer... Try using a combination of ls and find (this works for any file you have permission to remove) The '-i' parameter will give you the inode number for each directory entry ls -li 27 ---------- 1 owner group 3981 Oct 11 04:42 ????? Once you have the inode number... find . -inum **27** -exec rm -i {} \;


16

NMake is part of Microsoft's build tools for building C++ projects. You can get nmake as well as the MSVC++ compiler by downloading Visual C++ Express. Visual C++ Express runs perfectly fine on Windows 7.


15

Using sed: perl -e 'use Term::ANSIColor; print color "white"; print "ABC\n"; print color "reset";' | sed 's/\x1b\[[0-9;]*m//g' \x1b is the escape special character \[ is the second character of color statement [0-9]* is the color value m is the last character of color statement sed is enough, but you can still use perl instead of sed: perl -e 'use ...


13

Give rm ./- a try. The - is a flag to start a flag argument. If you start the argument with anything but a -, in this case /, it will assume it's the file name. Which is what you wish. And since file and ./file are the same file, it will target the file named - via ./-.


13

I had the same problem. I did: sudo port deactivate -f subversion-perlbindings-5.12 which allows me to install the new version of the perl bindings.


11

Here is an option using awk: awk '{ while(++i<=NF) printf (!a[$i]++) ? $i FS : ""; i=split("",a); print ""}' infile > outfile Edit Updated with comments: while (++i<=NF) Initializes the while loop, precrementing "i" since $0 is the full line in awk. So it starts at $1 (first field). Loops through the line until the end (less than or equal to ...


10

I use bash when my primary focus is on file handling. This could include moving, copying, and renaming files, as well as using files as input for other programs or storing other program's output in files. I rarely write bash code that actually examines the contents of a file or generates the output to write to a file; I leave that to the other programs ...


9

Try the --convert-links option: After the download is complete, convert the links in the document to make them suitable for local viewing. This affects not only the visible hyperlinks, but any part of the document that links to external content, such as embedded images, links to style sheets, hyperlinks to non-HTML content, etc.


8

You can filter any line or range of lines through an external command in vim, using !. E.g., you can do: :.!perl -pe "s/(\w+)/\u\1/g" which will filter the current line through that perl command. ( Here : to get into command line mode, and the . which follows mean the current line; you can also specify a line range or % for the whole file, etc.) If you ...


7

Not as geeky as most other answers, but I would fire up an instance of mc, midnight commander, and just select and delete the file.


7

UltraCopier UltraCopier is a free and cross-platform copy utility that is currently in development, so it's not that neat and polished yet. Once you install it, it sits in your menu bar. It manages a copy list that allows you to queue copy or move jobs, which are then sequentially processed. You can also define the copy process priority as well as the ...


7

To get the 64 bit version of nmake (for Windows 7) you can also install the Windows SDK. It will install nmake.exe to C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin on Windows 7 without prompting for an alternate directory.


7

Yes, using gunzip -c hugefile.txt.gz | head -n 4000000 is one way of tackling this problem (note the "-n", that was missing in your question). That would output the first 4000000 lines on standard out - you probably want to append another pipe to actually do something with the data. To get the other parts, you'd use a combination of head and tail, like: ...


7

As you are working on a (non-rewindable) stream, you will want to use the '+N' form of tail to get lines starting from line N onwards. zcat hugefile.txt.gz | head -n 40000000 zcat hugefile.txt.gz | tail -n +40000001 | head -n 40000000 zcat hugefile.txt.gz | tail -n +80000001 | head -n 40000000


7

find . -type f -name '*.*' -exec sh -c 'echo ${0##*.}' {} \; | sort | uniq -c | sort -nr The echo ${0##*.} gives you the extension of the file. We pipe the output to sort and then count the unique lines with uniq. Some additions: Since the output of uniq is not sorted according to the number of occurrences, you'll have to pipe again into a numeric sort ...


6

The Ubuntu package for Perl is simply "perl": sudo apt-get install perl which I think is preinstalled. To find a Perl module that's provided as an Ubuntu package: apt-cache search perl <module-name> For example: $ apt-cache search perl Config::IniFiles libconfig-inifiles-perl - Read .ini-style configuration files $ apt-cache search perl ...


6

You can easily determine the uptime in days with awk: # Print days of uptime, or zero if less than 1 day. uptime | awk '/days?/ {print $3; next}; {print 0}' You can use this with command substitution to perform any action you like based on the results. For example: #!/bin/bash days () { uptime | awk '/days?/ {print $3; next}; {print 0}'; } ...


6

sudo aptitude install libdbi-perl


6

This might be more of a SuperUser question, but I'd venture to say that the conflict is because you're trying to install a version of Perl for a different processor architecture on top of your current one. The packages aren't technically the same, since they're different architectures, so the package manager is trying to install them both at the same time ...


6

Try: $ ls -b to see if the filename has unprintable characters.


6

Not that it should be necessary to use perl here, but this should work: perl -e 'unlink "-"' or to see what any error with the above might be: perl -e 'unlink "-" or die "Err: $!"'


6

You can use $$ to get the process ID of the perl interpreter running your script: iancs-imac:Documents ian$ cat test.pl print "$$\n"; sleep(10000); exit() ians-imac:Documents ian$ perl test.pl 42291 In another shell: iancs-imac:~ ian$ sudo ps -ef | grep perl 501 42291 42281 0 0:00.00 ttys000 0:00.01 perl test.pl 501 42297 42280 0 ...


5

Because you’re using the wrong rename program. This is the right one.


5

You can set the http_proxy environment variable just for a specific invocation of wget: http_proxy=http://specific-squid-proxy-host:3129/ wget http://server/page


5

If you use apt-get and dh-make-perl for all packages, deborphan --guess-perl will find perl packages without any dependencies, which you can then remove and run it again iteratively. deborphan has a keep list which you can add the ones you're actively using to and they won't show up. So to make this work, you'll have to uninstall all the modules you ...



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