Schlagwort: Ubuntu

  • This is a solution for a , some without swap of some machine setup without swap where you need swap for something without wanting to fiddle with the drive partitions or so.

    This is a quick and dirty „short manual“ for based environments (such as , or ).

    First run this:

    cat > dphys-swap.sh << EOF
    #!/bin/bash
    #~/up
    apt-get install dphys-swapfile
    echo "CONF_SWAPSIZE=2048"|tee -a /etc/dphys-swapfile
    dphys-swapfile setup
    dphys-swapfile swapon
    systemctl restart dphys-swapfile.service
    systemctl status dphys-swapfile.service
    free -h
    EOF

    This will just create a short with the needed commands to run to get setup and running. Please alter the number 2048 to your need, it is the size of the swap memory that will be setup. The size of the swap should most likely by equal to the real memory installed, sometimes twice the size seems to be a good choice too.

    If you don’t know your memory size you can find it out by running the command „free -h“, which will print the size of the physical memory installed and the below this the swap size(s).

    After pasting the above code into your shell, which will create a file called „dphys-swap.sh“ in the current folder (you should be in your home folder!!), you need to make the shell script „dphys-swap.sh“ executable by running:

    chmod +x dphys-swap.sh

    Then you need to run the script like this:

    sudo ~/dphys-swap.sh

    It will ask for some confirmation(s) to install certain packages.

    The last commands will output the status of the systemd service „dphys-swapfile.service“ and the last line will show you the memory and swap size again.

    Remark:
    In the script above I use „up“, my full update of the system. I just blogged that one too, have a look here.

    Keine Kommentare zu Linux swap with dphys-swapfile
  • … is an easy to use and powerful tool, it can be used to replace part of file name (string1) with some other string. Something one can also do with some „sed“ hack, but this tool is much easier to use, especially for beginners.

    You can get all information needed from „rename –help“ (here from Linux Mint):

    rename --help
    Usage:
        rename [ -h|-m|-V ] [ -v ] [ -n ] [ -f ] [ -e|-E perlexpr]*|perlexpr
        [ files ]
    
    Options:
        -v, -verbose
                Verbose: print names of files successfully renamed.
    
        -n, -nono
                No action: print names of files to be renamed, but don't rename.
    
        -f, -force
                Over write: allow existing files to be over-written.
    
        -h, -help
                Help: print SYNOPSIS and OPTIONS.
    
        -m, -man
                Manual: print manual page.
    
        -V, -version
                Version: show version number.
    
        -e      Expression: code to act on files name.
    
                May be repeated to build up code (like "perl -e"). If no -e, the
                first argument is used as code.
    
        -E      Statement: code to act on files name, as -e but terminated by
                ';'.

    I did use this tool rename some files that contained the string „www“, which I had to replace with „web“, lets say there were files named like this:

    www.example.com-97126.ccd
    www.example.com-54852.ccd
    www.example.com-87430.ccd
    www.example.com-75413.ccd

    For Ubuntu, maybe also Debian, based systems I use the following command to rename all above files:

    rename -e 's/www/web/' *.ccd

    After this the files are now called
    web.example.com-….
    ….

    The only problem is, the syntax varies from one Linux distribution to another, so check the syntax before you use rename.

    For Arch Linux I found that something like this would work:

    rename www web *.ccd

    The expression „*.ccd“ defines which files to act on, so this will act on all files that match „*.ccd*, in the example above you could also use „www.example.com-*.ccd“ or something similar.

    Main thing I wanted to get out there is, there is an easy tool to batch rename files instead of some complex if-for bash code. Which I tried to use before but failed at.

    Keine Kommentare zu rename